javascript js:Window.open() 尝试打开本地文件夹失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34193253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
js:Window.open() for trying to open local folder failed
提问by MapleStory
I can not open local file ,meanwhile i use "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --allow-file-access-from-files on my shortcut of my google chrome. the explorer tips the security mode had been closed and I can open a new window using js or href attribute. But the question is :why each time I click the href ,it always open a blank page and nothing to display.so..
我无法打开本地文件,同时我使用 "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --allow-file-access-from-files 在我的我的谷歌浏览器的快捷方式。资源管理器提示安全模式已关闭,我可以使用 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# code:
C#代码:
partsQueryList[i].ImageRefLink = "<a onclick='copyUrl(this)' hreff='" + "C:\" + "' ><font color='blue'>ImageRefLink</font></a>";
btw,when I tried to use pushSate method ,it can push a new url to new window,but It can not solve crossdomain issue.so...how could I solve it?thanks!
顺便说一句,当我尝试使用 pushSate 方法时,它可以将新 url 推送到新窗口,但它无法解决跨域问题。所以......我该如何解决?谢谢!
回答by T???? M??????
You have 4 slashes instead of 3. Try this :
你有 4 条斜线而不是 3 条。试试这个:
var opener = window.open('file:///C:/windows');
Note: Also C:/windows doesn't seem like a valid file. Try with a valid file name.
注意:还有 C:/windows 似乎不是一个有效的文件。尝试使用有效的文件名。
Check this post for more help : Open a local HTML file using window.open in Chrome
查看此帖子以获取更多帮助:在 Chrome 中使用 window.open 打开本地 HTML 文件