contentwindow 和contentdocument dom对象和jquery对象
2013-11-11 17:05
387 查看
父页面调用iframe里的js函数
document.getElementById('iframedemo').contentWindow.demofunction(); //与下边一句等价
window.frames['iframedemo'].contentWindow.demofunction();
其中iframedemo是iframe的id,demofunction是iframe里的js函数名
父页面调用iframe里的dom元素
document.getElementById('iframedemo').contentDocument.getElementById("INPUT_Text").value; //与下边一句等价
window.frames['iframedemo'].contentDocument.getElementById("INPUT_Text").value;
其中iframedemo是iframe的id
注意事项:
contentwindow兼容各个浏览器,可取得子窗口的window对象
contentDocument firefox支持 ie8以上的支持
以上说的是父页直接调用父页面iframe里的dom或者是js函数,如果在子页面要调用父页面的js函数或者dom对象,
原理类似:
1 取得父页面的dom对象
var frameJqObj=$("[src='"+src+"']", window.parent.document);//window.parent.document父级窗体的document对象,jquery对象
var frameDomObj=frameJqObj.get(0);//get(num)返回的是个html对象,这个是dom对象
2 父页面调用iframe里的js函数
frameDomObj.contentWindow.demofunction();contentWindow属性是指指定的frame或者iframe所在的window对象
dom对象和jquery对象的转换
document.getElementById('iframedemo').contentWindow.demofunction(); //与下边一句等价
window.frames['iframedemo'].contentWindow.demofunction();
其中iframedemo是iframe的id,demofunction是iframe里的js函数名
父页面调用iframe里的dom元素
document.getElementById('iframedemo').contentDocument.getElementById("INPUT_Text").value; //与下边一句等价
window.frames['iframedemo'].contentDocument.getElementById("INPUT_Text").value;
其中iframedemo是iframe的id
注意事项:
contentwindow兼容各个浏览器,可取得子窗口的window对象
contentDocument firefox支持 ie8以上的支持
以上说的是父页直接调用父页面iframe里的dom或者是js函数,如果在子页面要调用父页面的js函数或者dom对象,
原理类似:
1 取得父页面的dom对象
var frameJqObj=$("[src='"+src+"']", window.parent.document);//window.parent.document父级窗体的document对象,jquery对象
var frameDomObj=frameJqObj.get(0);//get(num)返回的是个html对象,这个是dom对象
2 父页面调用iframe里的js函数
frameDomObj.contentWindow.demofunction();contentWindow属性是指指定的frame或者iframe所在的window对象
dom对象和jquery对象的转换
相关文章推荐
- $(document).ready()方法和window.onload有什么区别?Jquery对象和dom对象的区别?jQuery对象和dom对象是怎样转换的?
- jquery中的$(document).ready()、JavaScript中的window.onload()以及body中的onload()、DomContentLoaded()区别
- document.getElementById()与 $(),DOM对象和jQuery对象的转换
- $("#id")与document.getElementById("id") 即 jQuery对象和DOM对象相互转换
- jquery中的$(document).ready()、JavaScript中的window.onload()以及body中的onload()、DomContentLoaded()区别
- jQuery获得document和window对象宽度和高度的方法
- jquery中的$(document).ready()与window.onload的区别
- jQuery对象转成DOM对象
- Javascript中window对象、document对象的属性和方法(转)
- jQuery中的$(window).load()与$(document).ready()以及jquery $(document).ready() 与window.onload的区别
- 判断jQuery对象或dom对象是否存在
- 锋利的jQuery——window.onload与$(document).ready()对比
- jquery $(document).ready() 与window.onload的区别
- DOM对象和JQuery对象的区别
- jquery对象和DOM对象相互转换马克
- jquery $(document).ready() 与window.onload的区别
- Jquery对象和Dom对象如何转换
- jquery中的$(document).ready()与window.onload的区别
- [转载 js]document.body ,window.screen javascript对象属性取值意义
- window.document 对象