页面间(窗口间)的取值赋值及获取iframe下的window对象
2013-10-21 15:23
656 查看
①同一个窗口中,获取某个iframe的信息
var A = top.frames["PA"];//等效于document.getElementById("PAID").contentWindow
A获得的是iframe(PA)的上下文:window。
通过A可以操作该iframe的DOM对象和JS对象,例
在不跨域的情况下 ,如果想通过某个iframe中的window对象获取其所在iframe DOM的话,可以用以下方法解决
或者
这是因为window对象的name取自于iframe的id或name
②通过元素获取当前window对象(document)
③通过window.open方式的子窗口与父窗口进行交互
top.location.href 顶层frame地址
self.location.href 当前frame地址
获取父窗口焦点(只在IE下有效)
<body> <iframe id="PAID" name="PA" src="ItemSetting.htm"></iframe> <iframe id="DKID" name="DK" src="ItemSetting.htm"></iframe> </body>
var A = top.frames["PA"];//等效于document.getElementById("PAID").contentWindow
A获得的是iframe(PA)的上下文:window。
通过A可以操作该iframe的DOM对象和JS对象,例
var main = A.document.getElementById("mainDiv");//通过原生JS获取 var list = $(A.document).find("select");//通过JQ获取 var params = A.ParamList;//获取A页面中的JS对象 var values = A.getNames();//执行A页面JS中的Function
在不跨域的情况下 ,如果想通过某个iframe中的window对象获取其所在iframe DOM的话,可以用以下方法解决
//(前提是iframe必须有id) var id= window.name; var targetIframe = top.document.getElementById(id);
或者
window.frameElement
这是因为window对象的name取自于iframe的id或name
②通过元素获取当前window对象(document)
var but = document.getElementById("xxbut"); var doc = but.ownerDocument;
③通过window.open方式的子窗口与父窗口进行交互
var newWin = window.open(someUrl); var parentWin = window.opener; newWin是新打开的窗口的BOM对象 所以可以使用BOM的所有方法 常用的有 newWin.location.reload(true);//只有一个参数.true表示 newWin.focus(); newWin.close();等等 当然也可以获取到子窗口的JS对象和函数(参考①) parentWin 是打开该子窗口的BOM对象(不一定是父窗口,因为当初打开子窗口的有可能是父窗口中的iframe) 使用parentWin.top 就可以得到父窗口的window对象了
top.location.href 顶层frame地址
self.location.href 当前frame地址
通过 top.location.href==self.location.href 可确认当前页面是否被其他页面所装载
获取父窗口焦点(只在IE下有效)
window.opener.focus();
相关文章推荐
- 子窗口获取父页面对象
- window.open 和 window.showModelDialog 获取父窗口对象或属性的方式
- 怎么在html页面中获得iframe元素中的window对象?
- iframe中获取父元素的window对象
- 获取当前页面高度,赋值给父页面的iframe
- javascript刷新页面 (子窗口 window.open iframe)
- easyUi弹出window窗口传值与调用父页面的方法,子页面给父页面赋值
- iframe给主页面元素赋值【使用jquery获取页面数据】 .
- 获取iframe的window对象
- JQUERY 获取IFrame中对象或者在Iframe中获取父窗口中对象
- js 获取div里的值 2种方法给父窗口控件赋值和取值
- iframe获取焦点的问题、获取iframe src、打开新窗口window.open()
- 获取iframe父页面声明的变量值,获取iframe父页面对象
- JavaScript DOM编程基础精华01(DOM入门,DOM模型和获取页面元素,事件,window对象的方法)
- 获取游览器窗口的大小(window对象)
- JQuery获取iframe中window对象的方法
- js中获取当前页面高度,iframe高度赋值问题,body高度初始化赋值
- IE中使用window.open打开新窗口时无法获取Referrer对象
- JavaScript DOM编程基础精华01(DOM入门,DOM模型和获取页面元素,事件,window对象的方法)
- easyUi弹出window窗口传值与调用父页面的方法,子页面给父页面赋值