如何用JS操作iFrame里的Dom
2个回答
展开全部
<div id="myDiv">主页面</div>
<iframe id="myframe" width=420 height=330 ></iframe>
<script type="text/javascript">
var myframe=document.getElementById("myframe");
myframe.src=this.location.href;// 设置iframe的页面为当前页面
function invokemyframe(){
myframe.contentDocument.getElementById("myDiv").innerText+="\r\n--修改了--"
}
setTimeout(invokemyframe,200);// 收尾延迟下,等待iframe的页面加载
</script>
上面的代码保存为一个html文件,在浏览器打开就可以查看了。
展开全部
<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>�6�7
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
<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>�6�7
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询