Javascript 弹出窗口总是在顶部
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3602802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Popup window always on top
提问by Alec Smart
Am looking at whatever hacks that are possible to keep a window always on top (apart from window.focus()). Maybe a hidden textbox to which I can set focus etc.
我正在研究可能使窗口始终位于顶部的任何技巧(除了 window.focus())。也许是一个隐藏的文本框,我可以设置焦点等。
I see this happening in LivePerson (support) whenever a new message arrives. I have legitimate use of this and not to annoy users with ads or anything.
每当有新消息到达时,我都会在 LivePerson(支持)中看到这种情况。我有合法用途,不会用广告或任何东西来惹恼用户。
Any hacks for any browsers will do. I am not looking at a complete cross-browser solution. I think window.focus would work for Internet Explorer, though I am yet to test it.
任何浏览器的任何黑客都可以。我不是在寻找一个完整的跨浏览器解决方案。我认为 window.focus 可用于 Internet Explorer,但我尚未对其进行测试。
回答by Nick
This JavaScript code will place the popup window on top of all other open browser windows until the viewer closes the window containing this little JavaScript code:
此 JavaScript 代码会将弹出窗口置于所有其他打开的浏览器窗口之上,直到查看器关闭包含此小 JavaScript 代码的窗口:
<body onblur="self.focus();">

