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 ?
You 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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With