html窗口与其iframe子窗口之间的方法操作

1.父窗口操作iframe子窗口的js中变量、方法或dom对象

   js方法:

//父窗口获取子窗口js变量
document.getElementById("iframeId").contentWindow.jsVariable;
window.frames["iframeName"].window.jsVariable;
//父窗口获取子窗口js方法
document.getElementById("iframeId").contentWindow.jsMethod();
window.frames["iframeName"].window.jsMethod();
//父窗口获取子窗口dom
document.getElementById("iframeId").contentWindow.document.getElementById("domId");
window.frames["iframeName"].document.getElementById("domId");

  jquery方法:

//父窗口获取子窗口js变量
$("#iframeId")[0].contentWindow.jsVariable;
//父窗口获取子窗口js方法
$("#iframeId")[0].contentWindow.jsMethod();
//父窗口获取子窗口dom
$("#iframeId").contents().find("#domId");
$(window.frames["iframeName"].document).find("#domId");
$("#domId",document.frames('iframeName').document);

2.iframe子窗口操作父窗口的js中变量、方法或dom对象

    js方法:

//iframe子窗口获取父窗口js变量
window.parent.jsVariable;
//iframe子窗口获取父窗口js方法
window.parent.jsMethod();
//iframe子窗口获取父窗口dom
window.parent.document.getElementById('domId');

   jquery方法:

//iframe子窗口获取父窗口dom
$("#domId", parent.document);


仅供参考和完善,谢谢大家!

猜你喜欢

转载自blog.csdn.net/txp1993/article/details/48728879