2

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

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!

Anil D
  • 1,989
  • 6
  • 29
  • 60

2 Answers2

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:

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

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

I hope this helps!

Community
  • 1
  • 1
Márk Gergely Dolinka
  • 1,430
  • 2
  • 11
  • 22
0

for 5 seconds it is 5000. Try with

setTimeout(function() {
         window.close();
       }, 5000);
asifsid88
  • 4,631
  • 20
  • 30