[英]How my HTML application treats relative addresses depends too much on how it is run
My HTML application file F:\\relroot\\libname.lib\\textapp.hta
(name altered) contains the following function: 我的HTML应用程序文件F:\\relroot\\libname.lib\\textapp.hta
(名称更改)包含以下功能:
function fullNameOfFile(filename) {
var fso = newMedium(); return fso.GetAbsolutePathName(filename)
}
When I run the application via Open
or double-click it in the directory, 当我通过“ Open
运行该应用程序或在目录中双击该应用程序时,
fullNameOfFile("../etc.txt")
returns "F:\\relroot\\etc.txt"
[runs perfectly!]. fullNameOfFile("../etc.txt")
返回"F:\\relroot\\etc.txt"
[完美运行!]。
When I run it via Open with:Microsoft HTML Apln Host
, however: 当我通过Open with:Microsoft HTML Apln Host
运行它时:
fullNameOfFile("../etc.txt")
returns "C:/Windows/etc.txt"
[wrong number!]. fullNameOfFile("../etc.txt")
返回"C:/Windows/etc.txt"
[错误的数字!]。
How should I code to get to work regardless of how the application is run? 无论应用程序如何运行,我应该如何编码才能开始工作?
I think I might have "Aspie-rigged" a solution (or maybe two) 我想我可能有“ Aspie操纵”的解决方案(也许有两个)
Apparently opening the HTML application via Open (or double-click) presets the "current" directory to the directory containing the app while opening via Open With : Microsoft® HTML Application Host uses a default directory (like « C:\\WINDOWS\\system32
») 显然,通过开开 (或双击)的HTML应用程序预置的“当前”目录中包含的应用程序,同时通过打开方式打开目录: 微软HTML应用程序主机使用默认的目录(如« C:\\WINDOWS\\system32
» )
var shell = new ActiveXObject("WScript.Shell");
var wasDir = shell.currentDirectory /* OPTIONAL: push original current directory
to allow restoration later */
var swDL = false; // for differences in device file format
var splitter = (swDL ? '/' : '\\') // foreslash v. backslash
var slashes = (swDL ? '///' : '//') /* slashes between scheme/protocol
and authentication/host */
var lhref = swDL ? unescape(location.href) : document.URL;
var newDir = lhref.slice(location.protocol.length + slashes.length,
lhref.lastIndexOf(splitter));
/*
// uncomment this block for an "inside window"
alert("Entering Directory: «" + wasDir + "»\n" +
"Protocol/Scheme: «" + location.protocol + "»\n" +
"Location HREF: «" + lhref + "»\n" +
"Trial Directory: «" + newDir + "»");
*/
shell.currentDirectory = newDir
It seems to work like a charm on my system (Dell PC, Internet Explorer/¿Edge). 在我的系统(Dell PC,Internet Explorer /¿Edge)上,它的工作方式似乎很吸引人。 I threw in some comments as well in case the next user needs to tweak it for their system. 我还提出了一些意见,以防下一个用户需要对其系统进行调整。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.