Open link in new window or focus to it if already open

Different browsers behave differently for window.open() and focus().
For this code window.open('www.sample.com','mywindow').focus()

  • Chrome 20 opens a new tab, and focuses on subsequent open() calls regardless if focus() is called or not.
  • Firefox 13 opens a new tab, focuses on first open(), does not focus on subsequent open() calls/disregards focus().
  • IE 8 opens a new window, honors focus().
  • Safari 5 opens a new window, and focuses on subsequent open() calls regardless if focus() is called or not.

Fiddle to test with: http://jsfiddle.net/jaraics/pEG3j/

Leave a Comment