2017-02-13 99 views
0

我打開彈出窗口someurl.aspx。處理後重定向到父網址。但如果窗口找到父網址,我需要關閉它。如何在javascript中關閉基於url的彈出窗口

function openNewWin(url) { 
     window.location = '../../Portal/Billing/BillGeneration.aspx'; 
     var newwindow = window.open(url, 'popuprpt', 'width=940,height=700,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=10,top=5'); 

     var isPopup = (window.location.href == window.opener.location.href); 
     if (isPopup == true) { 
      newwindow.close(); 
     } 

     return false; 
    } 

但它沒有工作。如何實現它

回答

0

您可以訪問新打開的窗口的屬性。如果你正在檢查同一個域中的文件它只會工作,但在你的情況下,它應該工作:

var wn = window.open(.....); 

//!!! you also need to wait till the window is opened and loaded. 
setTimeout(function(){ 
    try{ 
     if(document.location.href === wn.document.location.href){ 
      // same url 
     } 
    }catch(ex){ 
     console.log(ex) 
    } 
}, 2000); 

此代碼將2秒

後運行檢查