[英]Load local files using iframe
I tried to load some files using iframe
, but it didn't work. 我试图使用
iframe
加载一些文件,但它没有用。
I want to load a file from: C:/Users/Tom/Desktop/Courses/c2.pdf and I tried: 我想从以下位置加载文件: C:/Users/Tom/Desktop/Courses/c2.pdf我试过:
<iframe src="file:///C:/Users/Tom/Desktop/Courses/c2.pdf"></iframe>
but nothing appears. 但没有出现。
How can I load local files using iframe
or something else? 如何使用
iframe
或其他方式加载本地文件? Thanks. 谢谢。
This is probably because of the Same Origin Policy: in this case the iframe is not allowed to load the resource if it is not also served from your localhost. 这可能是因为同源策略:在这种情况下,如果资源不是从您的localhost提供的,则不允许加载iframe。 See https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy for more info
有关详细信息,请参阅https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy
If you're serving html from the server (wamp,xamp) you should put it to local folder relative to the server (localhost/yourfolder/yourfile.pdf). 如果你从服务器(wamp,xamp)提供html,你应该把它放到相对于服务器的本地文件夹(localhost / yourfolder / yourfile.pdf)。 If you're just working with html it should work.
如果您只是使用HTML,它应该工作。 I've just tested it and had similar issue on chrome.
我刚刚测试了它并且在chrome上有类似的问题。 All of a sudden it started downloading pdf rather then render it.
突然间它开始下载pdf而不是渲染它。 So I had to reinstall browser in order for it to work.
所以我不得不重新安装浏览器才能使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.