打开一个新窗口,并在5秒后关闭该窗口

时间:2016-05-25 10:24:05

标签: javascript

我有一个应该打开身份验证窗口(IwAuthentication)的函数,并在关闭该窗口5秒后打开一个新窗口(IwUrl)。我尝试了很多代码而且我能够完成所有任务但是窗口。关闭它不起作用,我的IwAuthentication仍然打开。有什么建议吗?我的代码在下面

谢谢!

var IwAuthentication = "http://etc";
var IwUrl = "http://etc");

function openwindowAuthentication() {
    var myWindow = window.open(IwAuthentication, "myWindow", "width=500, height=500");
}

window.setTimeout(function () {
    window.open(IwsUrl, myWindow, "toolbar=yes, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
    closewindowAuthentication();
}, 5000);

function closewindowAuthentication() {
    myWindow = window.close();   // Closes the new window
}

2 个答案:

答案 0 :(得分:0)

试试这个

var myWindow = window.open(IwAuthentication, "myWindow", "width=500, height=500");

setTimeout(function () {
    myWindow.close();
}, 5000);

答案 1 :(得分:0)

你需要做两件事

  1. 在函数
  2. 之外声明变量myWindow
  3. 请参阅myWindow.close()而非window.close()
  4. var IwAuthentication = "http://etc";
    var IwUrl = "http://etc");
    var myWindow = null;
    
    function openwindowAuthentication() {
        myWindow = window.open(IwAuthentication, "myWindow", "width=500, height=500");}
    
        window.setTimeout(function () {
            window.open(IwsUrl, myWindow1, "toolbar=yes, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
            closewindowAuthentication();
        }, 5000);
    
    function closewindowAuthentication() {
         myWindow.close();   // Closes the new window
    }