Bring popup window forward

in my application, I have a popup with information that opens when I select some options.

first its ok, a popup in front of everything.

But, when he loses focus, when the user switches to another window, if the user clicks on the same option again, I want the pop-up window to be displayed again, in front of everything.

I will try something like:

<body onLoad="this.focus()"> window.focus(); document.focus(); this.focus(); 

but dos doesn't work for me.

What am I missing?

+6
source share
1 answer

You must save the link to the popup that you open and invoke the focus method on it.

 var win = window.open(url, name, args); win.focus(); 

When you open a popup, if you specify a name, and the next time you open a popup with the same name, it will use the same popup if it is not closed. You just need to focus it.

You can use this simple function to handle pop-ups.

 function windowOpener(url, name, args) { if(typeof(popupWin) != "object" || popupWin.closed) { popupWin = window.open(url, name, args); } else{ popupWin.location.href = url; } popupWin.focus(); } 
+14
source

Source: https://habr.com/ru/post/906888/


All Articles