Javascript 了解 Iframe 中的跨域问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14197653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Understanding Cross-Domain issue in Iframes
提问by user1522820
This question might seem silly but I need to understand this for clarity.
这个问题可能看起来很愚蠢,但为了清楚起见,我需要理解这一点。
According to my understanding, cross-domain problem is when the domain of the webpage which contains the IFRAME is different from the domain of the web-page opened in IFRAME.
根据我的理解,跨域问题是当包含 IFRAME 的网页的域与在 IFRAME 中打开的网页的域不同时。
Going by that logic, nothing should open in IFRAME ever.
按照这个逻辑,任何东西都不应该在 IFRAME 中打开。
When I embed a web-page "bottom:10700" in the IFRAME of my web-page "top:9700", it gives error.I am not able to see the contents in IFRAME. Error is Access denied in accessing property 'constructor'
当我在我的网页“top:9700”的 IFRAME 中嵌入一个网页“bottom:10700”时,它给出了错误。我无法在 IFRAME 中看到内容。错误是Access denied in accessing property 'constructor'
I am getting the error while accessing the contructor (_1.contructor)
访问构造函数 (_1.contructor) 时出现错误
isc.A.Function=function isc_isA_Function(_1){
if(_1==null) return false;
if(isc.Browser.isIE&&typeof _1==this.$a7) return true;
var _2=_1.constructor;
if(_2&&_2.$k!=null){
if(_2.$k!=1)return false;
if(_2===Function)return true
}
This script is run when home page of bottom is opened in an iframe contained in top.
当在包含在顶部的 iframe 中打开底部的主页时,将运行此脚本。
Is there any way, I can make this work. I mean can I set both the domains to be same. I don't have access to remote site's script.
有什么办法,我可以做这个工作。我的意思是我可以将两个域设置为相同。我无权访问远程站点的脚本。
Is resizing the frame after redering it once a cross-domain scenario. If not, then certainly remote site is trying to access the IFRAME element..How can I debug this??
在跨域场景重新绘制后调整框架的大小。如果没有,那么肯定是远程站点正在尝试访问 IFRAME 元素。我该如何调试?
采纳答案by oleq
Cross-domain issues are about the communication between iframes. You can always embed any iframe but, if domains differ, iframes cannot interact with each other e.g. execute JS, modify DOM etc.
跨域问题是关于 iframe 之间的通信。您始终可以嵌入任何 iframe,但是,如果域不同,iframe 无法相互交互,例如执行 JS、修改 DOM 等。
HTML5 provides a sandboxpropertythat re-enables particular features of the cross-domain iframe interaction. Be careful, it can be dangerous.
HTML5 提供了重新启用跨域 iframe 交互的特定功能的sandbox属性。小心,这可能很危险。
回答by semir.babajic
It is normal behavior for a page xyz.com to load in an iframe hosted on abc.com. However, you cannot change anything or access its content via code from parent abc.com.
在 abc.com 上托管的 iframe 中加载页面 xyz.com 是正常行为。但是,您不能通过父 abc.com 的代码更改任何内容或访问其内容。
Hope this helped.
希望这有帮助。

