在 JavaScript 中打开文件时出现访问被拒绝错误
当我尝试打开 window.open('file///C:\calendar.html')
它抛出
访问被拒绝错误
如何修复此问题?谢谢
When I try to open window.open('file///C:\calendar.html')
it throws
Access Denied error
How do I fix this? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,您将不被允许从客户端的文件系统打开文件,因为这会造成巨大的安全漏洞。没有浏览器允许这样做。
您可以使用签名脚本来做到这一点。有关详细说明,请检查:
http://www.mozilla.org/projects/security/components/签名脚本.html
这当然是特定于浏览器的。
Usually you'll won't be allowed to open files from the client's filesystem as this would pose a huge security hole. No browsers would allow it.
You could use signed scripts to do that. For a detailed description check:
http://www.mozilla.org/projects/security/components/signed-scripts.html
This is of course browser specific.
难道是结肠不见了?
'file:///C:\calendar.html'
编辑:可能还需要只使用两个正斜杠,并转义反斜杠:
'file://C:\\calendar .html'
。但不确定你是否可以通过 JavaScript 打开本地文件,就像其他答案所说的那样。Could it be that the colon is missing?
'file:///C:\calendar.html'
Edit: Might also need to do only two forward slashes, and escape the backslash:
'file://C:\\calendar.html'
. Not sure you can open local files via JavaScript though, like the other answer says.