检查一个窗口是否弹出? [英] Check whether a window is Popup or not?
本文介绍了检查一个窗口是否弹出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个问题不是如果窗口弹出的重复,但类似的问题。
This question is not the duplicate of if window is popup , But a similar one.
我正在开发一个将脚本注入所有网页的扩展。我需要检测窗口是否弹出。
I am developing a extension which injects scripts to all web pages. I need to detect whether the window is popup or not.
注意:
我不是那个打开弹出窗口的人,所以上面的解决方案赢了't work。
Note: I am not the one who is opening the popup window, So the above solution won't work.
推荐答案
在Chrome,Firefox,Safari和IE8中测试时,以下方式适用于我。它适用于使用window.open()或target = _blank创建的窗口。
The following worked for me when testing in Chrome, Firefox, Safari, and IE8. It worked for a window created useing window.open() or target=_blank.
if (window.opener) {
alert('inside a pop-up window or target=_blank window');
} else if (window.top !== window.self) {
alert('inside an iframe');
} else {
alert('this is a top level window');
}
这篇关于检查一个窗口是否弹出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文