如何用JS操作iFrame里的Dom
2个回答
2014-12-04 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517180
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
<body>
<iframe id="container" name="container" src="frames/index.html"></iframe>
</body>
在chrome的console里:
document.getElementById("container")
Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
<iframe id="container" name="container" src="frames/index.html">...</iframe>
document.getElementById("container").contentWindow.document
Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
undefined
window.frames["container"].document
Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
undefined
虽然是相对路径,还是出现跨域的错误。
最后找到原因了,文件之间的操作是按照跨域处理的,把文件放在web容器里,127.0.0.1 去访问就好了
<iframe id="container" name="container" src="frames/index.html"></iframe>
</body>
在chrome的console里:
document.getElementById("container")
Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
<iframe id="container" name="container" src="frames/index.html">...</iframe>
document.getElementById("container").contentWindow.document
Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
undefined
window.frames["container"].document
Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
undefined
虽然是相对路径,还是出现跨域的错误。
最后找到原因了,文件之间的操作是按照跨域处理的,把文件放在web容器里,127.0.0.1 去访问就好了
启帆信息
2024-11-22 广告
2024-11-22 广告
作为启帆信息科技股份有限公司的工作人员,对于Omniverse View有一定了解。Omniverse View是NVIDIA Omniverse平台中的一个强大工具,它易于导航且功能丰富,可以支持任何技能水平的专业人员展示和审查3D设计项...
点击进入详情页
本回答由启帆信息提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询