Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need to open a new window in the background with JavaScript, and make sure the original is still focused

Tags:

I have a window I'm opening with a Javascript function:

function newwindow()  {  window.open('link.html','','width=,height=,resizable=no');  } 

I need it that once the new window opens that the focus returns to the original window. How can I do that? And where do I put the code - in the new window, or the old one? Thanks!

like image 990
IsaacL Avatar asked Feb 02 '10 02:02

IsaacL


People also ask

How would you use JavaScript to open a new browser window?

In JavaScript, window. The window. open() method is used to open a new browser window or a new tab depending on the browser setting and the parameter values.

Which of the following method is used to open a new window using JavaScript?

Window open() Method. You can use JavaScript to launch a new window. The window. open() method, which allows you to open up new browser window without navigating away from the current page.


1 Answers

This is known as a 'pop-under' (and is generally frowned upon... but I digress).. It should give you plenty to google about

You probably want to do something like:

var popup = window.open(...); popup.blur(); window.focus(); 

Which should set the focus back to the original window (untested - pinched from google). Some browsers might block this technique.

like image 184
ChadT Avatar answered Oct 03 '22 17:10

ChadT