问题描述
我在我的网站上懒加载第三方广告脚本,通过覆盖document.write函数并在以后恢复它。此广告脚本会创建一个iframe,并尝试向其写入。
I am "lazy loading" a 3rd party ad script on my website by overwriting the document.write function and restoring it at a later time. This ad script creates an iframe, and tries to write to it.
我在 Internet Explorer 8 中看到访问被拒绝错误(但不是在FF,Safari或Chrome中)脚本尝试访问frame.document时。框架存在(我可以在IE8开发者工具中看到它)
I am seeing an "Access is denied" error in Internet Explorer 8 (but not in FF, Safari, or Chrome) when the script tries to access frame.document. The frame exists (I can see it in IE8 Developer Tools)
知道为什么会这样吗?可能是因为iframe还没有准备好,或者因为跨站点安全限制(我还不完全理解)?
Any idea why this is happening? Could it be because the iframe is not ready or because of cross-site security restrictions (which I don't fully understand)?
推荐答案
只是在没有看到您的代码的情况下在黑暗中拍摄,但检查您是否在页面上明确设置了document.domain。如果您正在设置文档的域,尝试访问动态注入的iFrame可能会在IE中引发访问错误。例如,如果设置了以下内容,请尝试将其评论为仅测试:
Just a shot in the dark here without seeing your code, but check to see if you have document.domain explicitly set on your page. If you are setting the domain of the document, trying to access a dynamically injected iFrame can throw access errors in IE. For example, if the following is set try commenting it out just to test:
//document.domain = "mydomain.com";
这篇关于“访问被拒绝”当脚本尝试访问IE8中的iframe时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!