Javascript focus tabs in Firefox
Posted: Thu Mar 19, 2009 3:58 pm
Hi all,
I've got some JS code that creates a new window for a given URL, then re-focuses that window if the link is clicked again. The code is posted below.
The problem I'm having is that my Firefox is set to open new tabs instead of new windows, and the focus() method isn't focusing the appropriate tab. When I run this code in Safari - which is set to open a new window, the focusing works fine.
Any ideas?
I've got some JS code that creates a new window for a given URL, then re-focuses that window if the link is clicked again. The code is posted below.
The problem I'm having is that my Firefox is set to open new tabs instead of new windows, and the focus() method isn't focusing the appropriate tab. When I run this code in Safari - which is set to open a new window, the focusing works fine.
Any ideas?
Code: Select all
$("a[rel=new]").click(function(){
var href = $(this).attr('href');
/* Determine if this url has been opened before */
/* If so, re-focus() it */
for(var i in newWindows)
{
if(newWindows[i].href == href && newWindows[i].object.closed == false){
newWindows[i].object.focus();
return false;
}
}
/* Create a new window & store it for checking later */
var newWindow = window.open($(this).attr('href'),'window_'+newWindows.length);
newWindows[newWindows.length] = { href: href,
object: newWindow
};
return false;
});