如何用JS操作iFrame里的Dom
2个回答
2014-12-04 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517181
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向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 去访问就好了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询