how to prevent reopening new window using jQuery?

风格不统一 提交于 2019-11-28 12:28:48

You could do:


var childWin;
    function winOpen(url)
    {
       //check if child window is already open
       if (childWin &! childWin.closed && childWin.focus){
           childWin.focus();
       } else {
          childWin = window.open(url,'','width=800,height=600');
      }
    }

Did you mean something like this

You can try this, it will help you to open and observe multiple windows, check here

Javascript

var windows = {};
$('a').click(function(e){
    var url = $(this).attr('href');
    var name = $(this).attr('id');
    if(windows.hasOwnProperty(name) && !windows[name].closed ) 
    {
       windows[name].focus();   
    }
    else  
    {
       windows[name]=window.open (url,name,"status=1,width=300,height=300");
    }    
});

Your Links

<a href="http://google.com" id="google">Google</a>
<a href="http://yahoo.com" id="yahoo">Yahoo</a>​

DEMO.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!