file:/// to http:// communication via IFrame

六眼飞鱼酱① 提交于 2019-12-22 08:57:54

问题


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? :(


回答1:


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.



来源:https://stackoverflow.com/questions/1568607/file-to-http-communication-via-iframe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!