Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to prevent reopening new window using jQuery?

I've recently posted a new question in How jQuery can prevent reopening a new window?. At that post, I mentioned to my need for something on F2 key.
Now I want to ask another question similar to the question above; This time for clicking on a link.
I have a link that opens a new window using window.open. I want to prevent user to reopening new window when he clicks on the list if the previous window is still opened.

What is your suggestion?

like image 608
Mohammad Saberi Avatar asked Feb 22 '12 07:02

Mohammad Saberi


Video Answer


2 Answers

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.

like image 160
The Alpha Avatar answered Sep 19 '22 06:09

The Alpha


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

like image 33
Sudhir Bastakoti Avatar answered Sep 19 '22 06:09

Sudhir Bastakoti