AliRıza Adıyahşi
AliRıza Adıyahşi

Reputation: 15866

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.

Upvotes: 1

Views: 1131

Answers (2)

AliRıza Adıyahşi
AliRıza Adıyahşi

Reputation: 15866

I solve the problem And It works with all browser.

here is code :

String MyScript = "";
MyScript += "<script language='javascript'>";
MyScript += "   window.open('', '_self', '');";
MyScript += "   top.window.close();";
MyScript += "</script>";
Page.ClientScript.RegisterClientScriptBlock(GetType(), "PopupClose", MyScript);

Upvotes: 1

nunespascal
nunespascal

Reputation: 17724

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.

Upvotes: 2

Related Questions