如何找出具有给定名称的窗口是否打开 [英] How to find out whether a window with the given name is open

查看:34
本文介绍了如何找出具有给定名称的窗口是否打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在第一次访问时打开弹出窗口.如果弹出窗口关闭,我想在下次刷新时重新打开弹出窗口.我尝试使用 cookie,但我不知道如何收到关闭窗口以删除 cookie 的通知.

I want to open the popup window on first visit. If the pop up is closed, I want to reopen the pop up on next refresh. I tried with cookies, but I could not figure out how to be notified of closing the window to delete the cookie.

是否可以通过使用window.name来了解窗口是否打开?

Is it possible to learn if window is open by using window.name?

喜欢

if (window.name==MsgWindow) 
{
    openWin();
}

function openWin()
{
    myWindow=window.open('','MsgWindow','width=200,height=100');
    myWindow.document.write("<p>This window's name is: " + myWindow.name + "</p>");
}

推荐答案

如果只有窗口的名称,我认为没有直接的方法可以检查窗口是否仍然打开.

I think there is no direct method to check whether a window is still open if you only have the window's name.

但是,对于您的情况,您可以执行以下操作:

However, for your case you could do the following:

// get reference to 'MsgWindow' (will open a new blank window if popup has been closed)
var popupWindow = window.open('', 'MsgWindow', 'width=200,height=100');

// keep popup window in background
window.focus();

// if popup window is blank (= has been closed before), load content
if (popupWindow.location.href == "about:blank") {
    popupWindow.location.href == /* your popup url here */;
}

这篇关于如何找出具有给定名称的窗口是否打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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