当尝试读取 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'
仍然是同样的问题,任何解决方案都会有帮助。
最佳答案
您违反了同源政策。添加:
document.domain = abc.com
到两个页面。可以直接在脚本标记中,也可以在引用的 js 文件中。
关于javascript - iframe同源策略问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38204432/