Open Bug 357379 Opened 14 years ago Updated 2 years ago

opener.focus() doesn't focus the tab that opened the actual one

Categories

(Core :: DOM: Core & HTML, defect, P5)

1.8 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: winter, Unassigned)

References

()

Details

(Keywords: regression)

Attachments

(2 files)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1) Gecko/20061010 Firefox/2.0
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1) Gecko/20061010 Firefox/2.0

page #1 opens a new window/tab with <a href="..." target="someNewWinName"/> to call page #2.

in page #2 there is a javascript doinng:

opener.location.href = '...';
opener.focus();

FF 2.0 RC 3 calls the right URL in page #1 but the correponding tab doesn't focus.

use case: http://www.geotrace.net/gm/?lang=en (click there on the left icon right to the photo thumbnails on the right. a new win/tab should open and get focus)

in this new page there are links back to the previous page ("map" top right of the page and "Word map" bottom right of the photograph) these links call a new map in the first tab/win, but the tab doesn't get focus



Reproducible: Always

Steps to Reproduce:
see above
Actual Results:  
no focus on thab with opener.focus().

Expected Results:  
focus on the opener tab.
Go to Options > Content > Javascript > Advanced. Is "Raise or lower windows" checked?
(In reply to comment #1)

no it wasn't checked, but checking  it (also with restart) didn't make it work.

btw. i'd rather see settings like allow/forbid "Raise or lower windows" being URL depended such loading of images is. there are applications like the given mapping example that are both extensive in loaded data and use of AJAX that do not fit in a classical history back/forward schema. here is a new windows a solution. but not if focus cannot be set when it is forbidden for spaming content (what's a good idea)
A minimized testcase that demonstrates the bug would be great.
Assignee: nobody → general
Component: Tabbed Browser → DOM
Product: Firefox → Core
QA Contact: tabbed.browser → ian
Version: unspecified → 1.8 Branch
needs page2.html in order to work.
needs page1.html in order to work.
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0

Do you have new "pages" set to open in tabs or windows? This works fine for me when I set the "New pages should be opened in a: new window" preference and enable windows to be lowered or raised.

When I have them set to open in new tabs, a new tab is opened when I click the link in page1.html and when I click the link in page2.html the page1.html tab seems to reload, but it's not focused. This happens both with the "Raise or lower windows" preference is enabled.

FWIW, 1.5 was shipped with the "Raise or lower windows" pref. enabled by default, whereas 2.0 and current trunk have this disabled.
Keywords: regression
OS: Windows XP → All
Hardware: PC → All
> Do you have new "pages" set to open in tabs or windows? 

i have the 2.0RC3 default, that is open in new tab.

 
> When I have them set to open in new tabs, a new tab is opened when I click the
> link in page1.html and when I click the link in page2.html the page1.html tab
> seems to reload, but it's not focused. This happens both with the "Raise or
> lower windows" preference is enabled.


yes, that's it and that is the problem from my point of view. what is it worth to be able eo talk to a win/tab (the win/tab #1 effectively loads a new url) and not being able to bring it to the foregroud?
I've come across this same behavior.

Let me see if I can sum up the behavior I'm experiancing.  I have a named window/tab which I want to be able to bring to focus from another window/tab.  The document in both tabs are from the same domain.  In cases where the tabs are in the same browser window I am able to switch focus to the intended tab. If the tabs are in separate windows and the tab I wish to focus is the currently selected tab in it's window, I am able to bring that window to focus.  If the tabs are in separate windows and the tab I wish to focus is not the currently selected tab I am unable to bring either the window or the tab to focus.  I have the allow JavaScript to Raise/Lower windows preference checked.

I know that there are some security concerns with allowing scripts to arbitrarily change focus etc, but we're currently able to do it across full browser windows, and there don't seem to be a huge number of exploits in the wild.

I managed to create a workaround that is acceptable for my current purposes, but is not generally applicable to most web sites or web-app developers.

If you're able to run your script as a signed script, or if your end user has signed.applets.codebase_principal_support set to true (It's disabled by default as is allows JS to attempt to run arbitrary code), you can use the following code to focus a specific tab in a specific window.
							netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
    .getService( Components.interfaces.nsIWindowMediator );
var windowEnumerator = wm.getEnumerator( null );
var url = window.location.href.substring(0, 
    ( window.location.href.indexOf( "/views" ) + 1 ) );
var found = false;
while( windowEnumerator.hasMoreElements() && !found ){
    var currentWindow = windowEnumerator.getNext();
    var numTabs = currentWindow.getBrowser().mPanelContainer.childNodes.length;
    for( var i = 0; i < numTabs && !found; i++ ){
        var currentTab = currentWindow.getBrowser().getBrowserAtIndex( i );
        if( currentTab.currentURI.spec.indexOf( url ) != -1 ){
            currentWindow.getBrowser().mTabContainer.selectedIndex = i;
            currentWindow.focus();
            found=true;
        }
    }
}

Obviously something like this is not anywhere near ideal for the simple case of bringing a window/tab to focus.  As a fix I'd suggest something along the lines of the cross domain and/or parent/child JavaScript security restrictions which currently exist, but applied to window.focus().
Regression from bug 310825?
Yes!  This bug is very much a regression from bug 310825 (and i have no idea how to make that hyper link...).
Duplicate of this bug: 399458
Assignee: general → nobody
QA Contact: ian → general
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046

Move all DOM bugs that haven't been updated in more than 3 years and has no one currently assigned to P5.

If you have questions, please contact :mdaly.
Priority: -- → P5
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.