简体   繁体   English

超时后ASP.NET javascript关闭页面?

[英]ASP.NET javascript close page after timeout?

I want show an information page after success db opartions. 我想在成功db opartions之后显示一个信息页面。 And after the info I want to close each pages (information page and main page) 在信息之后我想关闭每个页面(信息页面和主页面)

I wrote this in button oncommand event: 我在按钮oncommand事件中写了这个:

//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. 谢谢。

Firefox would only allow window.close(); Firefox只允许window.close(); and only if you opened the window with a script. 并且只有当您使用脚本打开窗口时。

Refer: window.close 参考: 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. 仅允许对使用window.open方法由脚本打开的窗口调用此方法。 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. 如果脚本未打开窗口,则JavaScript控制台中将显示以下错误:脚本可能无法关闭脚本未打开的窗口。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM