Html 跨浏览器链接到本地系统上的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1254572/
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
Cross-browser link to file on local system
提问by Ole Lynge
I would like to make a link from a web page to a file on a local filesystem and make it work in all browsers (or at least in Internet Explorer, Firefox and Chrome).
我想建立一个从网页到本地文件系统上的文件的链接,并使其在所有浏览器中都能工作(或至少在 Internet Explorer、Firefox 和 Chrome 中)。
For example, the following works in Internet Explorer:
例如,以下在 Internet Explorer 中有效:
<a href="\myserver\doc\info.pdf">Info here</a>
but not in Firefox and Chrome.
但不是在 Firefox 和 Chrome 中。
Is there a way to make a link that works in all browsers?
有没有办法制作一个适用于所有浏览器的链接?
Or a way to use javascript to detect which browser it is and then display the appropriate link based on the filename?
或者一种使用javascript来检测它是哪个浏览器然后根据文件名显示适当链接的方法?
采纳答案by sleske
Links to local files on pages that were retrieved via HTTP(S) are deliberately disabled in Mozilla/Firefox, because they can be a security risk, and have been used in attacks in the past.
通过 HTTP(S) 检索的页面上本地文件的链接在 Mozilla/Firefox 中被故意禁用,因为它们可能存在安全风险,并且过去曾被用于攻击。
You can override this behaviour, however. For details, see this articlein MozillaZine.
但是,您可以覆盖此行为。有关详细信息,请参阅MozillaZine 中的这篇文章。
回答by smercer
try prefixing your url with file:///
尝试使用 file:/// 为您的网址添加前缀