Focus Adjust pop-up window

I have a popup called myWindow, and when it pops up, I want the focus to be in the original window, not the popup. I pulled the line myWindow.focus(); and still focused on the popup. Does anyone know how to maintain focus on the original window when creating a popup? Live Long and Prosper.

 <!DOCTYPE html> <html> <head> <script type="text/javascript"> function openWin() { myWindow=window.open('','','width=200,height=100'); myWindow.document.write("<p>This is 'myWindow'</p>"); myWindow.focus(); } </script> </head> <body> <input type="button" value="Open window" onclick="openWin()" /> </body> </html> 
+4
source share
3 answers

Just call window.focus() immediately after opening the popup window, either in the function or immediately after it:

 <input type="button" value="Open window" onclick="openWin(); window.focus();" /> 

or

 function openWin() { myWindow=window.open('','','width=200,height=100'); myWindow.document.write("<p>This is 'myWindow'</p>"); window.focus(); } 
+3
source

Call window.focus() instead of myWindow.focus() .


If this does not work, try blurring the window, and then reconfigure it:

 window.blur(); window.focus(); 
+4
source

I ran into the same problem. I found a workaround.

I changed like this:

 myWindow.document.write("<p>This is 'myWindow'</p>"); myWindow.document.write("<script>window.opener.focus();</script>"); 

It worked for me in FF and Chrome.

+1
source

All Articles