2017-02-13 10 views
0

ポップウィンドウsomeurl.aspxを開いています。親URLへのリダイレクトを処理した後しかし、ウィンドウが親のURLを見つけたら、私は閉じる必要があります。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秒

後にチェックが実行されます
関連する問題