Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bring popup to front

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 ?

like image 795
Ricardo Binns Avatar asked Jan 25 '12 19:01

Ricardo Binns


1 Answers

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(); 
 }
like image 102
ShankarSangoli Avatar answered Sep 21 '22 18:09

ShankarSangoli