3

Does anyone have a clue on how to be able to use window.focus() in FireFox? (27.0.1). I have tried all the about:config settings out there but still no luck.

My code looks something like this:

var wi = window.open('myUrl');
wi.focus();

== EDIT ==

I'm trying to make this work in FireFox on my machine, not for any other users so please refrain from the standard "let your users decide" or "it depends on the user's settings" as I want to get this to work for a local project :)

Kevin Op den Kamp
  • 565
  • 1
  • 8
  • 22

2 Answers2

3

According to Window.focus specification from Mozilla, that's not possible. It depends on the user's settings.

Makes a request to bring the window to the front. It may fail due to user settings and the window isn't guaranteed to be frontmost before this method returns.

rpax
  • 4,468
  • 7
  • 33
  • 57
3

Tools > Options, Content area, "Advanced" button to the right of "Enable JavaScript" should give you the option to allow this behavior. If you're on Linux, the navigation might be slightly different.

Note, it is generally considered best practice to allow the user to choose what window should be in focus.

EDIT:

This is about:config you're referring to: dom.disable_window_flip

In FF 27.0.1 I am able to open a new window with focus by providing window name and option parameters to window.open, and then calling focus.

var wi = window.open('http://www.google.com', 'window_name', 'height=200,width=200');
wi.focus();

Example here: http://jsfiddle.net/CLVh2/

For Chrome support, you'll want to check out: Google Chrome "window.open" workaround?

EDIT: FOR TAB SUPPORT

If you want to open a tab and give the tab focus in FF (27.0.1), and simply calling window.open('url') is not giving you the desired result, try checking the "When I open a new tab, switch to it immediately" option. It can be found in Tools > Options > Tabs

Community
  • 1
  • 1
turing_machine
  • 473
  • 3
  • 13