简体   繁体   English

将弹出窗口放在前面

[英]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 ?我错过了什么?

You should maintain a reference to the popup window you open and call focus method on it.您应该维护对您打开的弹出窗口的引用,并在其上调用 focus 方法。

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(); 
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM