页面间(窗口间)的取值赋值及获取iframe下的window对象

①同一个窗口中,获取某个iframe的信息


<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();

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/TiestoRay/p/2660524.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值