Javascript focus tabs in Firefox

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Javascript focus tabs in Firefox

Post by pickle »

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?

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;
    });
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Javascript focus tabs in Firefox

Post by JAB Creations »

I think this is an issue that has been raised on the HTML5 forums and is being addressed in general in HTML5. I am a mod there but I personally don't like the general direction HTML5 is going though you may find something close to what you want there. Good luck! :)
Post Reply