单击按钮时,将打开子窗口。然后,如果再次单击它,则重新加载该页面。即使重新加载父页面,我也试图避免这种情况发生。只要子页面'test'打开,我希望click事件中的条件对子窗口不执行任何操作并发出警告。这可能吗?感谢
$('#send').click(function(){
if(*child page already open*){
alert('already open');
}else{
window.open("test.html","Ratting","width=550,height=170,0,status=0,");
}
});
答案 0 :(得分:4)
您需要测试子窗口是否存在 是否仍然打开:
var childWindow;
$('#send').click(function(){
if (childWindow && !childWindow.closed) {
alert('already open');
} else {
childWindow = window.open("test.html","Ratting","width=550,height=170,0,status=0,");
}
});
答案 1 :(得分:1)
var childPage = null;
$('#send').click(function(){
if(childPage && !childPage.closed){
alert('already open');
} else{
childPage = window.open("test.html","Ratting","width=550,height=170,0,status=0,");
}
});