免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
window.opener 的用法

1>window.opener 的用法

在一般的用法中,只是用來解決關(guān)閉窗口時(shí)不提示彈出窗口,  而對它更深層的了解一般比較少。其  實(shí)  window.opener是指調(diào)用window.open方法的窗口。
    在工作中主要是用來解決部分提交的。這種跨頁操作對工作是非常有幫助的。
如果你在主窗口打開了一個(gè)頁面,并且希望主窗口刷新就用這個(gè),打開頁面的window.opener就相當(dāng)于
主窗口的window。
主窗口的刷新你可以用
 window.opener.location.reload();
如果你用虛擬的目錄:如struts的*.do會(huì)提示你重試

你可以改成這樣 window.opener.yourformname.submit()
 就好了

2〉

在應(yīng)用中有這樣一個(gè)情況,
在A窗口中打開B窗口,在B窗口中操作完以后關(guān)閉B窗口,同時(shí)自動(dòng)刷新A窗口


function closeWin(){
        hasClosed = true;
        window.opener.location="javascript:reloadPage();";
        window.close();
    }
    function window.onbeforeunload(){
        if(!hasClosed){
            window.opener.location="javascript:reloadPage();";
        }
    }

</script>
上面的代碼在關(guān)閉B窗口的時(shí)候會(huì)提示錯(cuò)誤,說缺少Object,正確的代碼如下:
function closeWin(){
        hasClosed = true;
        window.opener.location="javascript:reloadPage();";
        window.opener=null;
        window.close();
    }
    function window.onbeforeunload(){
        if(!hasClosed){//如果已經(jīng)執(zhí)行了closeWin方法,則不執(zhí)行本方法
            window.opener.location="javascript:reloadPage();";
        }
    }

</script>
reloadPage方法如下:
function reloadPage() {
        history.go(0);
        document.execCommand("refresh")
        document.location = document.location;
        document.location.reload();
    }
PS:由于需要支持正常關(guān)閉和強(qiáng)制關(guān)閉窗口時(shí)能捕捉到事件,用了全局變量hasClosed

==============================================

補(bǔ)充,在父窗口是frame的時(shí)候在刷新父窗口的時(shí)候會(huì)出現(xiàn)問題:

The page cannot be refreshed without resending the information.
后修改如下: 
window.opener.parent.document.frames.item(‘mainFrame‘).location.href = window.opener.location.href;
不需要執(zhí)行自帶的reload()方法,注意,不要再畫蛇添足加上這一句:

window.opener.parent.document.frames.item(‘mainFrame‘).location.reload();

========================================================================================
最后,為了同時(shí)支持刷新普通父窗口和frame父窗口,代碼如下:
function closeWin() {
        hasClosed = true;
    <%if(null != frame){%>
        window.opener.parent.document.frames.item(‘mainFrame‘).location.href = window.opener.location.href;
    <%}else{%>
        window.opener.location = "javascript:reloadPage();";
    <%}%>
        //window.opener.top.mainFrame.location="javascript:reloadPage();";
        //self.opener.frames.mainFrame.location.reload(true);
        window.opener = null;
        window.close();
    }
    function window.onbeforeunload(){
        if (!hasClosed) {
        <%if(null != frame){%>
            window.opener.parent.document.frames.item(‘mainFrame‘).location.href = window.opener.location.href;
        <%}else{%>
            window.opener.location = "javascript:reloadPage();";
        <%}%>
            window.opener = null;
        }
    }

 

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
父頁面點(diǎn)擊a標(biāo)簽跳轉(zhuǎn)子頁面后 window.opener為null
轉(zhuǎn):用Javascript來關(guān)閉IE瀏覽器和FireFox瀏覽器
js 子窗口刷新父窗口
javascript用window.open的子窗口關(guān)閉自己并且刷新父窗口
JS 用window.open()函數(shù),父級頁面如何取到子級頁面的返回值
彈出頁修改后刷新父窗體
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服