无法关闭浏览器窗口

时间:2015-01-22 15:09:35

标签: javascript jquery

我正在使用

打开窗口
var childWindow = window.open('test.php','test',attributes);

在test.php中我有一个表单来插入数据,onclick提交按钮这个窗口应该关闭。 为此,我在点击提交按钮上写window.close();但我无法关闭窗口。 请帮帮我......

感谢。

2 个答案:

答案 0 :(得分:0)

因此,如果你打开一个窗口:

window.open("test.php", "test");

您可以关闭该窗口:

window.close("test");

答案 1 :(得分:0)

来自MDN:

[https://developer.mozilla.org/en-US/docs/Web/API/Window.open][1]

How do I know whether a window I opened is still open?


 You can test for the existence of the window object reference which 
is the returned value in case of success of the window.open() 
call and then verify that windowObjectReference.closed 
return value is false.

因此,在弹出窗口打开的主窗口中 - 运行setInterval函数以检测windowObjectReference.closed是否返回false

var myOpenWindow=window.open(...)
var interval = window.setInterval(function() {
        try {
            if (myOpenWindow == null || myOpenWindow.closed) {
                window.clearInterval(interval);
                //do something
            }
        }
        catch (e) {
        }
    }, "seconds to poll");
相关问题