繁体   English   中英

我的HTML应用程序如何处理相对地址,很大程度上取决于它的运行方式

[英]How my HTML application treats relative addresses depends too much on how it is run

我的HTML应用程序文件F:\\relroot\\libname.lib\\textapp.hta (名称更改)包含以下功能:

function fullNameOfFile(filename) { 
     var fso = newMedium(); return fso.GetAbsolutePathName(filename)
}

当我通过“ Open运行该应用程序或在目录中双击该应用程序时,

fullNameOfFile("../etc.txt")返回"F:\\relroot\\etc.txt" [完美运行!]。

当我通过Open with:Microsoft HTML Apln Host运行它时:

fullNameOfFile("../etc.txt")返回"C:/Windows/etc.txt" [错误的数字!]。

无论应用程序如何运行,我应该如何编码才能开始工作?

我想我可能有“ Aspie操纵”的解决方案(也许有两个)

显然,通过开 (或双击)的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

在我的系统(Dell PC,Internet Explorer /¿Edge)上,它的工作方式似乎很吸引人。 我还提出了一些意见,以防下一个用户需要对其系统进行调整。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM