您的位置:首页 > Web前端 > JavaScript

iframe父子页面相互调用的js方法(二)

2013-11-29 11:55 696 查看
从iframe中查找父页面中对象的方法:

JS:

查看源代码复制到剪贴板打印

[window.]parent //查找父页面的window对象

[window.]parent.document //查找父页面的document对象

[window.]parent.document.body //查找父页面的body对象

[window.]parent.document.getElementById('button') //查找父页面中id为button的对象

jQuery:

查看源代码复制到剪贴板打印

$([window.]parent) //查找父页面的window对象

$([window.]parent.document) //查找父页面的document对象

$([window.]parent.document.body) //查找父页面的body对象

$([window.]parent.document.body).find('#button') //查找父页面中id为button的对象

ta的签名:无怨无悔我走我路

从父页面中查找iframe子页面中对象的方法:

JS:

查看源代码复制到剪贴板打印

document.getElementById('iframe').contentWindow //查找iframe加载的页面的window对象

document.getElementById('iframe').contentWindow.document //查找iframe加载的页面的document对象

document.getElementById('iframe').contentWindow.document.body //查找iframe加载的页面的body对象

document.getElementById('iframe').contentWindow.document.getElementById('icontent') //查找iframe加载的页面的id为icontent的对象

jQuery:

查看源代码复制到剪贴板打印

$iframe.contents() //查找iframe加载的页面的document对象

$iframe.contents().find('body') //查找iframe加载的页面的body对象

$iframe.contents().find('body').find('#icontent') //查找iframe加载的页面的id为icontent的对象
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: