Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  168] [ 4]  / answers: 1 / hits: 15788  / 12 Years ago, mon, september 10, 2012, 12:00:00

I'm trying to get the window.focus() function to work with no luck.



Take a look at this fiddle



var myWindow = window.open('','zzz','width=600,height=700');
myWindow.document.write('test');
myWindow.focus();​


If you click run after the jsfiddle page loads then the new window should get back focus. What am I doing wrong?


More From » firefox

 Answers
495

It works for me in FF 15. Users can disable the ability of scripts to open and focus windows, check your settings. Oh, and the pop–up should get focus by default, so you shouldn't have to call myWindow.focus().



Some minor points that probably having nothing to do with the issue but you may want to fix:




  1. A valid document should be written to the new window, a title element and one block element are required, e.g. document.write('<title></title><div></div>, a DOCTYPE is highly recommended too

  2. The input stream should be closed after you've finished writing, use document.close()


[#83165] Friday, September 7, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cortez

Total Points: 326
Total Questions: 106
Total Answers: 110

Location: Slovenia
Member since Wed, Apr 6, 2022
2 Years ago
;