如果窗口弹出 [英] if window is popup

查看:81
本文介绍了如果窗口弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法确定当前窗口是否是弹出窗口?这就是我现在所拥有的,但由于某种原因,它不起作用。我试图确保某些页面只显示在弹出窗口中。

Is there a way to determine if the current window is a popup? This is what I have right now but for some reason it is not working. I am trying to make sure that certain pages are only shown in popup window.

if(!opener)
window.location = 'error.php';

即使窗口没有弹出窗口,opener的值也是[object DOMWindow]。

The value of opener is [object DOMWindow] even though the window is not popup.

推荐答案

假设你自己打开弹出窗口 - 设置一个标志:

Assuming you're opening popup windows yourself- set a flag:

var myWindow = window.open(...);
myWindow.isPopup = true;

然后,在弹出窗口中,检查标志:

then, in your popup window, check for the flag:

if (!window.isPopup) {
    window.location = 'error.php';
}

这篇关于如果窗口弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆