iframe子窗体和父窗体互相调用,通过document.getElementById("name_iframe").contentWindow获取iframe的window对象,支持多浏览器!
2014-03-27 23:28
1021 查看
父窗体:<html> <head> <title>usually function</title> </head> <body> <iframe src="http://www.baidu.com" ></iframe> <iframe src="myifame.html" id="name_iframe" name="name_iframe"></iframe> <button value="buttonvalue" id="testid">buttonvalue</button> </body> <html> <script type="text/javascript" src="jquery-1.4.4.js"></script> <script> //contentWindow这个属性,相当于获取iframe网页里面的window对象 $(function(){ //父窗体获取子窗体的变量 alert(document.getElementById("name_iframe").contentWindow.vname);//父窗体获取子窗体的方法 document.getElementById("name_iframe").contentWindow.test();//父窗体获取子窗体的内容 alert(document.getElementById("name_iframe").contentWindow.document.body.outerHTML); });
var myname="hb"; function parentFunction(){ alert("parentFunction"); } </script>
iframe窗体:
<html> <head> <title>usually function</title> </head> <body> <button onclick="getParentContent()">getParentContent</button> </body> <html> <script type="text/javascript" src="jquery-1.4.4.js"></script> <script>
var vname="v_name"; function test(){ alert("function test"); }
function getParentContent(){ //获取父窗体的变量 alert(window.parent.myname); //获取父窗体的方法 window.parent.parentFunction(); //获取父窗体的dom节点 alert(parent.document.getElementById("testid").value); } </script>
var myname="hb"; function parentFunction(){ alert("parentFunction"); } </script>
iframe窗体:
<html> <head> <title>usually function</title> </head> <body> <button onclick="getParentContent()">getParentContent</button> </body> <html> <script type="text/javascript" src="jquery-1.4.4.js"></script> <script>
var vname="v_name"; function test(){ alert("function test"); }
function getParentContent(){ //获取父窗体的变量 alert(window.parent.myname); //获取父窗体的方法 window.parent.parentFunction(); //获取父窗体的dom节点 alert(parent.document.getElementById("testid").value); } </script>
相关文章推荐
- 不区分不行的弱类型脚本中的有类型对象-iFrame通过document.getElementById方法访问和document.nameIframe的差异
- 发票名称<iframe name=document.getElementById("cellFrame").src = "dyszAction!showFpDyMb.do?fpzldm=" + fpzldm;
- js通过document.getElementById获取不到对象
- document.getElementById("idName")用js方法获取元素,则设定风格属性的方法为
- jquery 根据name属性获取对象(=document.getElementByName("") )
- getElementById;getElementsByName;getElementsByTagName获取对象的区别
- 调用js报错:try { document.getElementById("").SetReturnValue(__flash__toXML(MY_FUNCTION(
- if (document.all&&document.getElementById) 判断浏览器是否同时支持documnet.getElementById和document.all两种表述方式(方法)
- document.getElementById("xxx") 获取table中td的元素,length = 0 但,console打印出有元素--bootstraptable动态table
- javascript在html中的加载顺序------为什么window.alert(document.getElementById("time").innerTex)无法弹出对话框
- getElementById;getElementsByName;getElementsByTagName获取对象的区别
- getElementById;getElementsByName;getElementsByTagName获取对象的区别
- 为什么document.getElementById("idname")取不到组件
- js判断document.getElementByid("")获得的对象是否存在
- 获取HTML元素3个方法:document.getElementsByName()、document.getElementById()、document.getElementsByTagName()
- document.getElementById("radFs")对象为空,js判断对象是否存在?
- document.getElementById获取控件对象为空的解决方法
- ajax调用时,document.getElementById获取不到值
- js通过getElementById或getElementsByClassName()【】等方式获取元素为null或undefined
- 在JavaScript中使用document.getElementById()获取对象失败的原因