从父窗口关闭子窗口 [英] Closing child window from parent window

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

问题描述

我无法弄清楚为什么这不起作用。这段代码有问题吗?正在调用该函数我通过警告检查但它不会关闭窗口。

I cant figure out why this won't work. Is there something wrong with this code? The function is being called I checked with an alert but it just won't close the window.

 $('#click').click(function() {
   var win = window.open("test3.html","something","width=550,height=170");
 });

 function closeit(){
   win.close();
 }

和test3.html

and on test3.html

 window.opener.closeit();


推荐答案

您的胜利变量的范围限定为处理click事件的函数。将它放在该函数和 closeit 共享的范围内。

Your win variable is scoped to the function that handles the click event. Put it in a scope shared by both that function and closeit.

在这种情况下,这可能看起来像:

In this case, that would probably look like:

var win;

…

    $('#click').click(function() {
        win = window.open("test3.html", "something", "width=550,height=170");
    });
});

function closeit() {
    win.close();
}

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

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