window.open()详解

博客介绍了JS中window.open的返回值,指出window.opener是通过其打开窗体的父窗体。还阐述了使用window.open和模态窗口window.showModelDialog弹出子窗口时,在子窗口调用父窗口方法的情况,以及子窗口给父窗口传值、刷新父窗口并关闭当前窗口的操作,同时对比了window.parent和window.opener的用法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

语法

window.open(URL,name,specs,replace)
var specs="height=400,width=600,alwaysRaised,directories=no,toolbar=no,titlebar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no";

返回值:
oNewWindow : 对象(Element)。返回对新的 window 对象的引用。

window.opener 实际上就是通过window.open打开的窗体的父窗体。

当弹出子窗口使用的是 window.open();
在子窗口调用父窗口的方法:

 1 . parent.method();
 2 . opener.method();

当弹出窗口使用的是模态窗口 window.showModelDialog();
在子窗口调用父窗口的方法:

1 . var parentObj = window.dialogArguments;
    parentObj.method(); 

子窗口给父窗口传值的时候

window.parent.opener.document.getElementById("A431").value= “12345”;

刷新父窗口并关闭当前窗口

    function refreshParent() {       
           window.opener.location.href = window.opener.location.href;
            //通常在使用window.opener的时候要去判断父窗口的状态,
            //如果父窗口被关闭或者更新,就会出错,
            //解决办法是加上如下的验证if(window.opener && !window.opener.closed)
            
                      if (window.opener.progressWindow)     {          
                             window.opener.progressWindow.close();       
                      }      
                     window.close();   
             }  

window.parent和window.opener的用法

1.window.parent----是iframe页面调用父页面对象

  var parentWin=window.parent;
  parentWin.form.username.value="12345";

2.window.opener----是window.open打开的子页面对象调用父页面对象

  window.parent.opener.document.getElementById("A431").value= “12345”;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值