Various answers suggesting using any form of .focus()
will most likely not work in all browsers.
This one is used to work on the same day, but nothing more, mainly due to the fact that browsers actively stop shadow ad networks from pushing pop-up ads to the forefront.
Mozilla Firefox, in particular (depending on your version), has a configuration option that is enabled by default, which stops other windows (for example, pop-ups) from focusing.
This parameter can be found on the about:config
page (test carefully!)
dom.disable_window_flip: true
If I remember correctly, this parameter was usually called ~ allow_raise_or_lower_windows *
Other browsers may implement something similar, but it’s quite simple if, by default, one of the main browsers blocks the use of .focus()
, so there’s not much when trying to call it.
As a result, the only solution I've seen works is to see if the window exists and it is not closed yet ... and if it is close, load the desired window.
function closePopupIfOpen(popupName){ if(typeof(window[popupName]) != 'undefined' && !window[popupName].closed){ window[popupName].close(); } }
when you open a popup, if there is a chance that it is already open (and looped behind other windows), you can call this function before trying to open the popup.
closePopupIfOpen('fooWin'); var fooWin = window.open('someURL', 'foo', '...features...');
Of course, the disadvantage is that if there was something “important” in this window (for example, partially filled), it will be lost.