簡體   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