In my application, I have a popup with information that open when I choose some options.
First time it's OK, popup highlights in front of everything.
But, when it loses focus, when the user goes to other window, if user clicks again in the same option, I want that the popup shows up again, in front of everything.
I tried something like:
<body onLoad="this.focus()">
window.focus();
document.focus();
this.focus();
but it does not work for me.
What am I missing ?
In my application, I have a popup with information that open when I choose some options.
First time it's OK, popup highlights in front of everything.
But, when it loses focus, when the user goes to other window, if user clicks again in the same option, I want that the popup shows up again, in front of everything.
I tried something like:
<body onLoad="this.focus()">
window.focus();
document.focus();
this.focus();
but it does not work for me.
What am I missing ?
Share Improve this question edited May 14, 2020 at 14:44 krlzlx 5,82214 gold badges49 silver badges59 bronze badges asked Jan 25, 2012 at 19:19 Ricardo BinnsRicardo Binns 3,2466 gold badges45 silver badges71 bronze badges1 Answer
Reset to default 15You should maintain a reference to the popup window you open and call focus method on it.
var win = window.open(url, name, args);
win.focus();
While opening a popup if you give a name and next time when you open a popup with the same name it will use the same popup if it is not closed. You just have to focus it.
You can use this simple function to handle popups
function windowOpener(url, name, args) {
if(typeof(popupWin) != "object" || popupWin.closed) {
popupWin = window.open(url, name, args);
}
else{
popupWin.location.href = url;
}
popupWin.focus();
}