0

单击按钮时,将打开一个子窗口。然后,如果再次单击它,它将重新加载该页面。即使重新加载父页面,我也试图避免这种情况发生。只要子页面“测试”打开,我希望点击事件中的条件不对子窗口执行任何操作并发出警告。这可能吗?谢谢

$('#send').click(function(){

   if(*child page already open*){
    alert('already open');
 }else{
        window.open("test.html","Ratting","width=550,height=170,0,status=0,");
      }
});
4

2 回答 2

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,");
    }
});
于 2013-02-27T21:19:28.927 回答
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,");
  }
});
于 2013-02-27T21:16:45.227 回答