如何从asp.net中的代码调用浏览器关闭事件 [英] How to call browser close event from code behind in asp.net

查看:305
本文介绍了如何从asp.net中的代码调用浏览器关闭事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我知道关闭浏览器的Java脚本代码是:

Hi,

i know that the java script code for closing browser is:

<script type="text/javascript" >
if (event.altKey==true && event.keyCode==0 )
{
}
</script>



但我想使用它的Web窗体的窗体加载事件.

请帮帮我.


谢谢你

Mohd Wasif



but I want to use it form load event of a web form.

Please help me.


Thanking You

Mohd Wasif

推荐答案

您不能.处理后面的代码时,页面不在浏览器中.仅在完成此处理后,页面才会发送到浏览器.这就是ASP.NET的工作方式.将页面发送到浏览器并立即关闭页面有什么意义?
You can''t. When the code behind is being processed the page is not in the browser. Only after this processing is complete will the page sent to the browser. This is how ASP.NET works. What would be the point in sending a page to the browser and immediately closing it?


您不能...不要浪费时间...
You cant...Don''t waste your time...


是否考虑在返回的页面的onload事件中放置方法调用?为此,将页面的body标记的ID设置为"BodyTag"之类的名称,为其赋予一个"runat ="server"''属性,然后在C#中为:

Considered putting a method call in the onload event of the page you return? To do this, set the ID of your page''s body tag to something like ''BodyTag'', give it a ''runat="server"'' attribute and then, in C# it would be:

BodyTag.Attributes.Add("onload", "window.close()");



这将在页面加载后立即关闭浏览器,但是!这是一个非常糟糕的主意.这是许多病毒,恶意软件和特洛伊木马发布网站所使用的功能-如果关闭用户的浏览器,您的网站将不会受到信任,并且会很烦人-用户(客户)总是最了解",因为俗话说得好,尤其是在关闭他们的浏览器时.

希望这会有所帮助,即使我不会考虑使用它:〜

埃德:)



This would close the browser as soon as the page is loaded, but! This is a very bad idea. This is a feature used by a lot of virus, malware and trojan distribution websites - you website will not be trusted and be very annoying if it closes a user''s browser - ''the user (customer) ALWAYS knows best'' as the saying goes, especially when it comes to closing their browser.

Hope this helps, even though I wouldn''t consider using it :~

Ed :)


这篇关于如何从asp.net中的代码调用浏览器关闭事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆