3

As we know, click <a href='a.html' target='abc'>...</a> will load a.html into a window named abc.

But if the abc window already exists, and i just want to bring it foreground instead of load a.html again into it, is there a way to do this?

Thanks a lot.

iacnats
  • 181
  • 1
  • 7
  • possible dupe: http://stackoverflow.com/questions/7174222/select-and-focus-an-already-existing-window – dewd Feb 22 '15 at 18:26
  • Have you tried anything? like maybe something as obvious as `abc.focus()` ? – Touffy Feb 22 '15 at 18:27
  • `var w = window.open('', 'abc', null); if (w) w.focus();` After some test, i found chrome, opera works well and w.focus() bringing it foreground, while firefox can get the handle of the named window but can not bring it foreground, while IE debuggger just says "Access is denied" when processing this line of code – iacnats Feb 23 '15 at 13:58

1 Answers1

0

Some browsers (FF and IE) prevent the focus behaviour because it's (was) abused for popup spam. It can be turned on through security settings but since it's off by default, the focus method is unreliable.

This is an old problem. Here is a discussion of the same problem from 2006!

http://bytes.com/topic/javascript/answers/482500-popup-focus-behaviour-moz-firefox-ie

A workaround is to close and reopen the window popup window for those browsers.

See here: How to focus on JS popups in Firefox & IE?

PS. It is generally advised that you shouldn't refocus a popup window programmatically. If you need to do something like this, a popup is not likely the best choice for the task.

Community
  • 1
  • 1
Fuzzy Logic
  • 304
  • 1
  • 9