使用JQuery一段时间后自动关闭窗口

时间:2021-12-01 17:04:15

I want to close a window automatically after 5 seconds using jQuery. This is what i tried but not working.

我想用jQuery在5秒后自动关闭一个窗口。这是我尝试过的,但没有成功。

function SubmitDesignRequestForm() {
    var frm = $("#frmDesignRequestForm").serialize();
    $.post("/Admin/SaveDesignRequestForm", frm, function(data) {
       Notify("Success", "Saved Successfully");
       setTimeout(function() {
         window.close();
       }, 500); 
     });
   });
}

But above function just show message but do not close windows.

但以上功能仅显示消息,不关闭窗口。

 setTimeout(function() {
        Notify("Success", "Saved Successfully");
        window.close();
    }, 5000);

From above function "Saved Successfully" pops up but window does not close.

从上面的函数“保存成功”弹出但窗口不关闭。

Please guide!

请指导!

2 个解决方案

#1


1  

The problem is not in your code, I tried an almost identical one: the data was an empty string but otherwise everything is the same.

问题不在您的代码中,我尝试了一个几乎相同的代码:数据是一个空字符串,但是其他的一切都是一样的。

And it worked perfectly, but only in Google Chrome, see these links for what the problem can be with Firefox and IE:

它运行得很好,但只有在谷歌Chrome中,可以查看这些链接,了解火狐和IE的问题:

Firefox: window.close() doesn't work on Firefox, any work around?

windows .close()对Firefox不起作用,有什么作用吗?

IE: How can I close a browser window without receiving the "Do you want to close this window" prompt?

IE:我怎么能关闭浏览器窗口而不收到“你想关闭这个窗口”的提示?

I hope this helps!

我希望这可以帮助!

#2


0  

for 5 seconds it is 5000. Try with

5秒是5000。试着用

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

#1


1  

The problem is not in your code, I tried an almost identical one: the data was an empty string but otherwise everything is the same.

问题不在您的代码中,我尝试了一个几乎相同的代码:数据是一个空字符串,但是其他的一切都是一样的。

And it worked perfectly, but only in Google Chrome, see these links for what the problem can be with Firefox and IE:

它运行得很好,但只有在谷歌Chrome中,可以查看这些链接,了解火狐和IE的问题:

Firefox: window.close() doesn't work on Firefox, any work around?

windows .close()对Firefox不起作用,有什么作用吗?

IE: How can I close a browser window without receiving the "Do you want to close this window" prompt?

IE:我怎么能关闭浏览器窗口而不收到“你想关闭这个窗口”的提示?

I hope this helps!

我希望这可以帮助!

#2


0  

for 5 seconds it is 5000. Try with

5秒是5000。试着用

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