How to prevent re-opening a new window using jQuery?

I recently posted a new question in How can jQuery prevent a new window from reopening? . In this post, I mentioned the need for something in the F2 key .
Now I want to ask another question, similar to the question above; This time for a click on the link.
I have a link that opens a new window with window.open. I want the user not to open a new window when he clicks on the list if the previous window is still open.

What is your suggestion?

+5
source share
2 answers

You can 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

+5
source

, ,

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");
    }    
});

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

DEMO.

+6

All Articles