【发布时间】:2016-07-05 13:14:27
【问题描述】:
在尝试读取 src 为其他域的 iframe 内容时出现以下错误
SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "https://qa-xxx.abc.com" from accessing a frame with origin "https://yyy.abc.com". Protocols, domains, and ports must match.
现在假设我现在在https://qa-xxx.abc.com doamin 并且我的 iframe 代码是
<iframe src="https://yyy.abc.com" style="height: 100%; width: 105%;" id="id_description_iframe"></iframe>
在搜索时我发现了这个解决方案Access-Control-Allow-Origin not working for iframe withing the same domain
所以我确实喜欢document.domain = 'abc.com'
同样的问题,任何解决方案都会有帮助。
【问题讨论】:
-
如果您不控制 iframe 中的代码,您将无法在其中执行任何操作。你两个都控制吗?
-
@charlietfl 我没听明白,你说的 iframe 代码控制是什么意思
-
Simple... 是您控制的域上的 iframe,您可以将代码放入该页面吗?
-
是的,我可以访问qa-xxx.abc.com,我只是在那里部署我的代码..
-
这两者之间究竟需要做什么?我过去使用过 document.domain。但是postMessage API也是有用的api
标签: javascript jquery iframe