处理浏览器关闭事件和页面刷新 [英] Handling Browser close event and Page Refresh

查看:91
本文介绍了处理浏览器关闭事件和页面刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用中需要处理的浏览器关闭事件。当用户直接关闭浏览器,我们应该给他一个警告信息,并通过直接关闭基于一些条件窗口阻止他。这我们已经通过身体onunload事件处理。问题是,我们所得到的警报消息,但显示了警告消息的窗口被关闭后。

In our application we need to handle browser close event. When a user directly closes the browser, we should give him an alert message and stop him by directly closing the window based on some conditions. This we have handled through body onunload event. The problem is we are getting the alert message but after showing the alert message the window gets closed.

有没有什么办法阻止收盘浏览器关闭事件单击窗口?

Is there any way to stop closing the window on click of browser close event?

和刷新页面时也,最后执行的动作是越来越再次被解雇。为避免这种请提供您的建议。

And also when the page is refreshed, the last performed action is getting fired again. Please provide your suggestions for avoiding this.

推荐答案

简短的回答你的第一个问题是:没有。在大多数浏览器应用级事件不能由code在网页中被停止。

The short answer to your first question is: no. Application-level events in most browsers cannot be stopped by code in your webpage.

有关你的第二个问题,你就需要把code要执行到条件块:

For your second question, you would need to put the code you want to execute into a conditional block:

if(!IsPostback)
{
   //execute my code.
}

这篇关于处理浏览器关闭事件和页面刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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