file:/// 到 http:// 通过 IFrame 进行通信
也许你们中的一些人可能遇到了我遇到的同样的问题。 假设您的计算机上有一个文件: file:///c:\test.html
并且该文件内有一个 IFrame。您需要指示 IFrame 内容是否已加载。
基本上,我们这里有: 1. 无法从 file:/// 到 http:/// 或向后访问位置、href 或任何其他属性。 2. 不幸的是,您无法从 iframe 中的浏览器窗口或相反的方向触发事件。
这个问题有解决办法吗? PS:这不是黑客。这是一个真正的问题。从本地计算机与网站集成进行一些交互。
UPD:我有点明白为什么它被禁止了。网页上应禁止与本地文件进行任何交互。这有点酷,我同意。但是 # 标签不是不能伤害任何人的吗? :(
Maybe some of you could have ran into the same problem i did.
Imagine you have a file on your machine: file:///c:\test.html
And you have an IFrame inside of this file. You need to indicate whether the IFrame contents are loaded or no.
Bacically, what we have here:
1. location, href, or any other property is inaccessible from file:/// to http:///, or backwards.
2. you can't fire event from the browser window in iframe, or in opposite direction, unfortunately.
Does this problem have a solution?
P.S.: that's not a hack. it's a real problem. making some interaction from local machine with website integration.
UPD: I kinda figure out why it's forbidden. ANY interaction with local files should be forbidden from the web page. It's kinda cool, i do agree. But isn't a # hashtag something that can't harm anyone? :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能会发现其中一些技术很有用: http://softwareas.com/cross-domain -communication-with-iframes
编辑:根据下面的评论,这些技术在访问
file:///c:\\test 时似乎不起作用.html
,而它们在访问http://localhost/test.html
时执行此操作。我认为这是因为
file
协议比http
协议更受浏览器的限制。 有关文件协议的 MSDN 页面指出:无论您使用什么技术来进行跨域通信,都可能被浏览器阻止,因为您使用的是
file
协议。You may find some of these techniques useful: http://softwareas.com/cross-domain-communication-with-iframes
Edit: Per comments below, these techniques don't seem to work when accessing
file:///c:\<path>\test.html
, whereas they do when accessinghttp://localhost/test.html
.I think that's because the
file
protocol is even more restricted by the browser than thehttp
protocol. The MSDN page on the file protocol states:Whatever technique you were using to get some cross-domain communication was probably blocked by the browser because you were using the
file
protocol.