Search code examples
javascriptasp.netcode-behind

ASP.NET javascript close page after timeout?


I want show an information page after success db opartions. And after the info I want to close each pages (information page and main page)

I wrote this in button oncommand event:

//but this code does not work
Response.Write("<script language='javascript'>setTimeout('self.close();',3000);</script>");

at the same time, I want to show an information message. And then I want to close all, after three seconds.I hope I could explain :)

Thanks.


Solution

  • Firefox would only allow window.close(); and only if you opened the window with a script.

    Refer: window.close

    When this method is called, the referenced window is closed.

    This method is only allowed to be called for windows that were opened by a script using the window.open method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.