file:/// 到 http:// 通过 IFrame 进行通信

发布于 2024-08-08 15:55:06 字数 405 浏览 4 评论 0原文

也许你们中的一些人可能遇到了我遇到的同样的问题。 假设您的计算机上有一个文件: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

杀手六號 2024-08-15 15:55:06

您可能会发现其中一些技术很有用: http://softwareas.com/cross-domain -communication-with-iframes

编辑:根据下面的评论,这些技术在访问 file:///c:\\test 时似乎不起作用.html,而它们在访问 http://localhost/test.html 时执行此操作。

我认为这是因为 file 协议比 http 协议更受浏览器的限制。 有关文件协议的 MSDN 页面指出:

Internet Explorer 6 Service Pack 1 (SP1) 不再允许浏览
来自 Internet 区域的本地计算机。例如,如果一个互联网站点
包含本地文件的链接,Internet Explorer 6 SP1 显示
当用户单击链接时出现空白页。以前版本的 Windows
Internet Explorer 跟随链接到本地​​文件。

无论您使用什么技术来进行跨域通信,都可能被浏览器阻止,因为您使用的是 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 accessing http://localhost/test.html.

I think that's because the file protocol is even more restricted by the browser than the http protocol. The MSDN page on the file protocol states:

Internet Explorer 6 Service Pack 1 (SP1) no longer allows browsing a
local machine from the Internet zone. For instance, if an Internet site
contains a link to a local file, Internet Explorer 6 SP1 displays a
blank page when a user clicks on the link. Previous versions of Windows
Internet Explorer followed the link to the local file.

Whatever technique you were using to get some cross-domain communication was probably blocked by the browser because you were using the file protocol.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文