检查是否关闭一个弹出窗口 [英] Check if a popup window is closed

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

问题描述

我打开一个弹出窗口

  VAR弹出= window.open('...','...');

这是JavaScript的一个控件定义。这种控制是然后从网页中。我想重装它打开时弹出关闭这个弹出页面。

基本上用户需要输入在弹出窗口中一些教派和提交。这些面额然后存储在用户会话。而当用户点击提交我关闭弹出窗口,并在同一时间想刷新它打开这个弹出窗口,以重新获取其用户在弹出所作的更新。

我试图做的。

  VAR弹出= window.open('...','...');
如果(弹出){
  popup.onClose =功能(){popup.opener.location.reload(); }
}

我想我做错了堂妹这并不似乎是工作。

有关测试的问题,我甚至试过,但没有出现警告。

 如果(弹出){
  popup.onclose =功能(){
    警报(1.InsideHandler);
    如果(揭幕战和放大器;&安培;!opener.closed){
      警报(2.Executed。);
      opener.location.reload(真);
    }其他{
      警报(3.NotExecuted。);
    }
  }
}


解决方案

下面是我的建议。

在弹出的有

<脚本类型=文/ JavaScript的>功能reloadOpener(){
  如果(top.opener&安培;&安培;!top.opener.closed){
    尝试{
      opener.location.reload(1);
    }
    赶上(E){}
    window.close()的;
  }
}
window.ununload =功能(){
  reloadOpener();
}
< / SCRIPT>

<形式的行动=...TARGET =hiddenFrame>
< /表及GT;
< IFRAME的风格=宽度:10px的;高度:10px的;显示:无NAME =hiddenFrameSRC =有关:空白>< / IFRAME>

然后在服务器进程回报

&LT,脚本>
top.close();
< / SCRIPT>


旧建议

有没有名为在弹出窗口中弹出变量。
尝试

  VAR弹出= window.open('...','...');
如果(弹出){
  popup.onclose =功能(){opener.location.reload(); }
}

或与测试

 <$ C C> popup.onclose =功能(){如果(揭幕战和放大器;&安培;!opener.closed)opener.location.reload(); }

PS:的OnClose 是不是所有的浏览器都支持

PPS:location.reload需要一个布尔值,如果要没有从缓存中加载添加真
 在 opener.location.reload(1);

I am opening a popup window with

var popup = window.open('...', '...');

This javascript is defined in a control. This control is then used from a web page. I want to reload the page which opens this popup when the popup is closed.

Basically user is required to input some denominations in the popup window and submit. These denominations are then stored in user sessions. And when user clicks submit I am closing the popup window and at the same time want to refresh the window which opens this popup to refetch the updates which user made in the popup.

I am trying to do

var popup = window.open('...','...');
if (popup) {
  popup.onClose = function () { popup.opener.location.reload(); }
}

I guess I am doing it wrong coz this isn't seems to be working.

For testing the issue I've even tried this but no alert appeared.

if (popup) {
  popup.onclose = function() { 
    alert("1.InsideHandler");
    if (opener && !opener.closed) { 
      alert("2.Executed.");
      opener.location.reload(true); 
    } else { 
      alert("3.NotExecuted.");
    }
  }
}

解决方案

Here is what I suggest.

in the popup have

<script type="text/javascript">

function reloadOpener() {
  if (top.opener && !top.opener.closed) {
    try {
      opener.location.reload(1); 
    }
    catch(e) {  }
    window.close();
  }
}
window.ununload=function() {
  reloadOpener();
}
</script>

<form action="..." target="hiddenFrame">
</form>
<iframe style="width:10px; height:10px; display:none" name="hiddenFrame" src="about:blank"></iframe>

then in the server process return

<script>
top.close();
</script>


Old suggestions

There is no variable called popup in the popup window. try

var popup = window.open('...','...');
if (popup) {
  popup.onclose = function () { opener.location.reload(); }
}

or with a test:

popup.onclose = function () { if (opener && !opener.closed) opener.location.reload(); }

PS: onclose is not supported by all browsers

PPS: location.reload takes a boolean, add true if you want to not load from cache as in opener.location.reload(1);

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

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