Html href="file://" 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12837024/
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
href="file://" doesn't work
提问by Sangsom
I have a problem with:
href="file://"
Well I want to point a link in html to file, in browser if I write like
我有一个问题:
href="file://"
好吧,我想将 html 中的链接指向文件,如果我这样写,则在浏览器中
file:///K:/filename.pdf
It works to open a file, but if I point it to:
它可以打开一个文件,但如果我指向它:
href="http://file:///K:/AmberCRO%20SOP/2011-07-05/SOP-SOP-3.0.pdf"
It doesn't work. link is changed to:
它不起作用。链接改为:
file///K:/AmberCRO%20SOP/2011-07-05/SOP-SOP-3.0.pdf
The colon
after file disappears. Any suggestions as to what to do?
在colon
以后的文件中消失。关于该怎么做的任何建议?
回答by inspite
The reason your URL is being rewritten to file///K:/AmberCRO%20SOP/2011-07-05/SOP-SOP-3.0.pdf
is because you specified http://file://
您的 URL 被重写的原因file///K:/AmberCRO%20SOP/2011-07-05/SOP-SOP-3.0.pdf
是因为您指定了http://file://
The http://
at the beginning is the protocol being used, and your browser is stripping out the second colon (:) because it is invalid.
在http://
一开始是使用的协议,您的浏览器剥出第二个冒号(:)因为它是无效的。
Note
笔记
If you link to something like
如果你链接到类似的东西
<a href="file:///K:/yourfile.pdf">yourfile.pdf</a>
The above represents a link to a file called k:/yourfile.pdf
on the k: drive on the machineon which you are viewing the URL.
以上代表了一个文件的链接,该文件在您正在查看 URL的机器上k:/yourfile.pdf
的 k: 驱动器上调用。
You can do this, for example the below creates a link to C:\temp\test.pdf
你可以这样做,例如下面创建一个链接 C:\temp\test.pdf
<a href="file:///C:/Temp/test.pdf">test.pdf</a>
By specifying file:// you are indicating that this is a local resource. This resource is NOT on the internet.
通过指定 file:// 您表明这是一个本地资源。该资源不在互联网上。
Most people do not have a K:/ drive.
大多数人没有 K:/ 驱动器。
But, if this is what you are trying to achieve, that's fine, but this is not how a "typical" link on a web page works, and you shouldn't being doing this unless everyone who is going to access your link has access to the (same?) K:/drive (this might be the case with a shared network drive).
但是,如果这是您要实现的目标,那很好,但这不是网页上“典型”链接的工作方式,除非每个要访问您的链接的人都可以访问,否则您不应该这样做到(相同?)K:/驱动器(共享网络驱动器可能就是这种情况)。
You could try
你可以试试
<a href="file:///K:/AmberCRO-SOP/2011-07-05/SOP-SOP-3.0.pdf">test.pdf</a>
<a href="AmberCRO-SOP/2011-07-05/SOP-SOP-3.0.pdf">test.pdf</a>
<a href="2011-07-05/SOP-SOP-3.0.pdf">test.pdf</a>
Note that http://file:///K:/AmberCRO%20SOP/2011-07-05/SOP-SOP-3.0.pdf
is a malformed
请注意,这http://file:///K:/AmberCRO%20SOP/2011-07-05/SOP-SOP-3.0.pdf
是一个畸形的
回答by Dipak
%20
is the space between AmberCRO SOP.
%20
是AmberCRO SOP 之间的空间。
Try -
尝试 -
href="http://file:///K:/AmberCRO SOP/2011-07-05/SOP-SOP-3.0.pdf"
Or rename the folder as AmberCRO-SOP and write it as -
或将文件夹重命名为 AmberCRO-SOP 并将其写为 -
href="http://file:///K:/AmberCRO-SOP/2011-07-05/SOP-SOP-3.0.pdf"
回答by Maximiliano Becerra
Share your folder for "everyone" or some specific group and try this:
为“所有人”或某个特定组共享您的文件夹,然后尝试以下操作:
<a href="file://YOURSERVERNAME/AmberCRO%20SOP/2011-07-05/SOP-SOP-3.0.pdf"> Download PDF </a>
回答by Roger Browne
Although the ffile:////.exe used to work (for example - some versions of early html 4) it appears html 5 disallows this. Tested using the following:
尽管 ffile:////.exe 曾经可以工作(例如 - 早期 html 4 的某些版本),但 html 5 似乎不允许这样做。使用以下方法进行测试:
<a href="ffile:///<path name>/<filename>.exe" TestLink /a>
<a href="ffile://<path name>/<filename>.exe" TestLink /a>
<a href="ffile:/<path name>/<filename>.exe" TestLink /a>
<a href="ffile:<path name>/<filename>.exe" TestLink /a>
<a href="ffile://///<path name>/<filename>.exe" TestLink /a>
<a href="file://<path name>/<filename>.exe" TestLink /a>
<a href="file:/<path name>/<filename>.exe" TestLink /a>
<a href="file:<path name>/<filename>.exe" TestLink /a>
<a href="ffile://///<path name>/<filename>.exe" TestLink /a>
as well as ... 1/ substituted the "ffile" with just "file" 2/ all the above variations with the http:// prefixed before the ffile or file.
以及... 1/ 仅用“file”替换“ffile” 2/ 上述所有变体都在 ffile 或文件之前加上前缀 http:// 。
The best I could see was there is a possibility that if one wanted to open (edit) or save the file, it could be accomplished. However, the exec file would not execute otherwise.
我能看到的最好的情况是,如果有人想打开(编辑)或保存文件,这是可以实现的。但是,exec 文件不会以其他方式执行。