javascript - iframe同源策略问题

标签 javascript jquery iframe

当尝试读取 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/

相关文章:

javascript - 相对定位的 div 内的绝对定位仍然没有留在原地

javascript - 如果屏幕宽度小于 800(移动设备),则完全删除 div

javascript - e = 事件 ||窗口.事件;声明在 Firefox 中无法正常工作

html - 带沙箱的 Iframe 不允许在 Firefox 中弹出新窗口/选项卡

javascript - 包裹在 IFrame 中时的网页限制?

javascript - 在正文中搜索关键字

javascript - 如何在 forEach 循环内赋值?

javascript - 无法更新表单中的值并发送到下一个 jsp 页面

php - 简化列表项选择性 jQuery 切换的代码

javascript - Iframe 的滚动条