js同域或跨子域读写操作 iframe 里的内容
2013-10-16 23:28
357 查看
1.父页面读写操作子页面:
<script>
//获取iframe的window对象
//var win = window.top.document.getElementById("iframeId").contentWindow;
//通过获取到的window对象操作HTML元素,这和普通页面一样
//var tId = win.document.getElementById("tableId");
/** 下面两种获取节点内容的方式都可以。
* 由于 IE6, IE7 不支持 contentDocument 属性,所以此处用了通用的
*window.frames[index] 支持火狐和ie
* window.frames["iframe Name"] or window.frames[index]
*/
var win = window.frames[0].document;
alert(win.getElementsByTagName('td')[0].innerHTML);
</script>
2.子页面读写操作父页面:
<script>
parent.document.getElementsByTagName('h1')[0].innerHTML = 'pp';
alert(parent.document.getElementsByTagName('h1')[0].firstChild.data);
</script>
<script>
//获取iframe的window对象
//var win = window.top.document.getElementById("iframeId").contentWindow;
//通过获取到的window对象操作HTML元素,这和普通页面一样
//var tId = win.document.getElementById("tableId");
/** 下面两种获取节点内容的方式都可以。
* 由于 IE6, IE7 不支持 contentDocument 属性,所以此处用了通用的
*window.frames[index] 支持火狐和ie
* window.frames["iframe Name"] or window.frames[index]
*/
var win = window.frames[0].document;
alert(win.getElementsByTagName('td')[0].innerHTML);
</script>
2.子页面读写操作父页面:
<script>
parent.document.getElementsByTagName('h1')[0].innerHTML = 'pp';
alert(parent.document.getElementsByTagName('h1')[0].firstChild.data);
</script>
相关文章推荐
- JQ&&JS获取并操作iframe内容
- 详解Node.js读写中文内容文件操作
- js操作Iframe(获取Iframe中的节点内容)
- JS操作Iframe获取到Iframe中的内容+ListView+DataPager分页
- 用JS操作FRAME中的IFRAME及其内容的实现代码
- Node.js读写中文内容文件操作
- JS操作iframe内容
- Node.js读写中文内容文件操作
- 用JS操作FRAME中的IFRAME及其内容
- 用JS操作FRAME中的IFRAME及其内容的实现代码
- Node.js读写中文内容文件操作
- Node.js读写中文内容文件操作
- 通过JS操作iframe中的内容,遇到的问题
- jquery/JS 操作iframe
- js代码:实现主页面滚动条随iframe里的内容自动调整
- JS操作iframe里的dom(转)
- JS访问Iframe中的内容的方法
- JS获取并操作iframe中元素的方法
- js操作iframe
- 用 js 的 selection range 操作选择区域内容和图片