如何识别打开的窗口是弹出窗口还是选项卡? [英] How do identify whether the window opened is a pop up or a tab?

查看:121
本文介绍了如何识别打开的窗口是弹出窗口还是选项卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在面对一个问题。我可以使用window.open方法打开一个窗口。如果我指定窗口的高度和宽度,它会以弹出窗口的形式打开。如果没有给出高度参数或宽度,然后它打开一个新的标签。

是否有任何属性,我可以确定窗口打开是一个弹出窗口或新标签?



谢谢
Malcolm X

解决方案

我一直在进一步研究这一点。



好像在这些窗口上没有不同的类型,只是不同的选项。
我发现检查它是否是选项卡或窗口的一种方法是检查 window.menubar.visible
对于这个标签,它是一个完整的普通窗口,它是 true ,对于弹出菜单,该菜单是隐藏的,因此。同样适用于 window.toolbar.visible



至少适用于FF和Chrome。不幸的是不在IE中。 (测试在IE8中完成,这是我安装的版本,用于测试当然..)

示例:

  if(window.menubar.visible){
// Tab
} else {
//ChildWindow
}

发现此主题:




如果指定宽度和高度,则意味着您还必须指定名称参数。这可以以与使用 a 标签中的 target 相同的方式使用,并且默认为 _blank



如果您不指定宽度和高度,我假设您也不指定 name ,因此它是用 name = _blank 打开的,这意味着一个新的Tab。



如果你指定宽度和高度,你是否设置了一个自定义名称?这样做会产生一个子窗口。如果你指定一个名字或空字符串作为名字,我建议你尝试 name:_blank ,如果你想让它成为一个新标签。

如果窗口是以名称打开的,则可以始终从子窗口中输入 window.parent 。如果用 _blank 打开,我不确定您是否可以获得 window.parent



w3schools窗口打开


I have been facing a problem.I am able to open a window using window.open method.If I specify the height and width of the window,it opens as a pop up window.If no parameters is given for height or width,then it opens in a new tab.

Is there any property through which I can determine window opened was a pop up or a new tab?

Thank you Malcolm X

解决方案

Edit: I have been looking into this a little further.

Seems like there is no different "type" on these windows, simply different options. A way I found to check if it was a tab or window is to check window.menubar.visible. For the tab, which is a full and normal window it is true, and for the pop-up the menu is hidden and therefore false. Same applies to window.toolbar.visible.

Works in FF and Chrome at least. Unfortunately not in IE. (Testing done in IE8, which is the version I have installed. For testing of course..)

Example:

if(window.menubar.visible) {
    //Tab
} else {
    //"Child" Window
}

Found this thread: Internet Explorer 8 JS Error: 'window.toolbar.visible' is null or not an object


If you specify width and height, it means that you also have to specify the name parameter. This can be used in the same way target in an a tag is used, and defaults to _blank.

If you do not specify width and height I assume you also don't specify name and therefore it is opened with name=_blank, which means a new Tab.

If you specify width and height, are you setting a custom name? Doing so results in a child window. If you specify a name, or empty string as name, I suggest you try name:_blank if you want it to be a new tab.

If the window was opened with a name, you can always the window.parent from the child window. If you open with _blank I am not sure if you can get the window.parent

w3schools Window Open

这篇关于如何识别打开的窗口是弹出窗口还是选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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