2012-02-22 112 views

回答

5

你可以这样做:

 

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

你的意思是这样

+0

没有新的窗口正在到来。即使我们第一次点击链接,它也会在同一个窗口中打开。 – 2014-03-19 08:50:30

6

你可以试试这个,它会帮助你打开和观察多个窗口,检查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"); 
    }  
}); 

您的链接

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

DEMO.

+2

这工作完美。 – 2014-03-19 08:52:16

+1

非常好!谢谢 ! – Zl3n 2016-01-08 21:17:45