我最近在How jQuery can prevent reopening a new window?上发布了一个新问题。在那个帖子中,我提到我需要的东西上F2键。
现在我想问一个类似于上面问题的问题;这次点击链接。
我有一个链接,使用window.open
打开一个新窗口。如果前一个窗口仍然打开,我想阻止用户在点击列表时重新打开新窗口。如何防止使用jQuery重新打开新窗口?
你的建议是什么?
我最近在How jQuery can prevent reopening a new window?上发布了一个新问题。在那个帖子中,我提到我需要的东西上F2键。
现在我想问一个类似于上面问题的问题;这次点击链接。
我有一个链接,使用window.open
打开一个新窗口。如果前一个窗口仍然打开,我想阻止用户在点击列表时重新打开新窗口。如何防止使用jQuery重新打开新窗口?
你的建议是什么?
你可以这样做:
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');
}
}
你的意思是这样
你可以试试这个,它会帮助你打开和观察多个窗口,检查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>
这工作完美。 – 2014-03-19 08:52:16
非常好!谢谢 ! – Zl3n 2016-01-08 21:17:45
没有新的窗口正在到来。即使我们第一次点击链接,它也会在同一个窗口中打开。 – 2014-03-19 08:50:30