2

When I run this code in Chrome, it swaps to the open named window, but in IE and firefox nothing happens

How can I get IE/ Firefox to swap to the existing window?

http://jsfiddle.net/M9TD3/5/

<script>
var myWindow = null;

  openWin = function(value){
     myWindow =  window.open('http://www.google.com','myWindow');
  };


swapToWindow = function(){
    if (myWindow !==null){
     window.open('','myWindow');
    }
};

</script>

1 Answer 1

0

Quite simply, as far as I've read, you can't with that particular method. In Firefox, the method to bring focus to a window is .focus, though like many javascript things, this depends on the settings of the user. I've noticed for instance, that it doesn't appear to work with tabs for me, but it works fine with windows.

See here as well.

It is 'roughly' the same with Internet Explorer; as stated in the documents: "For windows 8 and later, the focus method no longer brings child windows to the foreground. To bring the child window to the foreground, add script to the child window that acts on its window object."(paraphrased, see link for full text)

Working demo(Note: Only tested with windows, not tabs.)

3
  • The 'resizable' option was included to force the script to open a new window, since tabs don't always work.
    – Daedalus
    Sep 24, 2013 at 5:09
  • I tried the working demo but it only opens tabs in IE and firefox and doesn't focus to them, I also meant to say these are for tabs not physical windows open. When you open js windows (tabs in chrome) and call window.open('','windowName') it swops to that open tab
    – Martin
    Sep 25, 2013 at 6:01
  • @Martin I don't know how that could be; I specifically coded it so it wouldn't open tabs, but windows. I also linked the relevant documentation for each method in the relevant browser; as I already stated through the quoted documentation.. It's not possible to reliably do that. If you disagree, the documentation is there for you to read. In chrome, it may as well be a specific feature to that browser, there's no guarantee that its available in any other browser.
    – Daedalus
    Sep 25, 2013 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.