1

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.

3
  • I think the browser is just blocking your close script. Put some debug message and check if your function is being executed. Commented Jun 25, 2012 at 11:34
  • Which browser you using? Sadly you are in browser specific territory. Commented Jun 25, 2012 at 11:44
  • In modern browsers script can't close windows that were not opened by that script. People don't like websites closing their browsers and I can totally agree to that. Commented Jun 25, 2012 at 11:45

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Not on all browsers, it would work on older versions of IE. But There are better ways to present notifications to users. Floating divs, dialog windows(there are asp.net controls dedicated to do that), etc. These you can open/close very easily using scripts.
1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.