【问题标题】:js:Window.open() for trying to open local folder failedjs:Window.open() 尝试打开本地文件夹失败
【发布时间】:2016-03-15 13:53:18
【问题描述】:

我无法打开本地文件,同时我使用“C:\Program Files (x86)\Google\Chrome\Application\chrome.exe” --disable-web-security --allow-file-access-from-我的谷歌浏览器快捷方式上的文件。 资源管理器提示安全模式已关闭,我可以使用 js 或 href 属性打开一个新窗口。 但问题是:为什么每次我点击href,它总是打开一个空白页面,没有任何显示。所以..

function copyUrl(obj)
{
var href = $(obj).attr("hreff");
var hideInput = $("#hidInputHref");
hideInput.val(href);
hideInput.select();
try
{
    document.execCommand('copy');
    var opener = window.open('file:////C:/windows');
   // opener.document.write("<iframe src='c:\' width='100%' height='100%'></iframe>");
    //var test = "<body><script>" +
    //    "alert(1);console.log(1);"
    //"<" + "\/script><div>11111111111</div></body>";

    ////var stateObj = { foo: "bar" };

    //opener.document.write(test);

    //opener.history.pushState("", "page 2", "./a.html");
    //opener.location.href = "www.baidu.com";
    //opener.location.reload();

    opener.opener.location.href = "C:\windows";

}
catch (err)
{
    console.log(err);
}

}

C#代码:

partsQueryList[i].ImageRefLink = "<a onclick='copyUrl(this)' hreff='" + "C:\\" + "' ><font color='blue'>ImageRefLink</font></a>";

顺便说一句,当我尝试使用 pushSate 方法时,它可以将新 url 推送到新窗口,但它不能解决跨域问题。所以...我该如何解决呢?谢谢!

【问题讨论】:

    标签: javascript google-chrome


    【解决方案1】:

    你有 4 个斜线而不是 3 个。试试这个:

    var opener = window.open('file:///C:/windows');
    

    注意:C:/windows 似乎也不是一个有效的文件。尝试使用有效的文件名。

    查看此帖子以获得更多帮助:Open a local HTML file using window.open in Chrome

    【讨论】:

    • 嗨,我只想打开一个文件夹而不是一个文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-06
    • 2016-08-26
    • 1970-01-01
    • 2013-03-20
    相关资源
    最近更新 更多