我打开pop窗口someurl.aspx。处理重定向到父URL后。但是如果窗口找到父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 :(得分: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秒后运行检查