Page 1 of 1

Javascript focus tabs in Firefox

Posted: Thu Mar 19, 2009 3:58 pm
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;
    });

Re: Javascript focus tabs in Firefox

Posted: Sun Mar 22, 2009 4:15 am
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! :)