Reputation: 1683
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.
Upvotes: 2
Views: 2511
Reputation: 19635
The short answer to your first question is: no. Application-level events in most browsers cannot be stopped by code in your webpage.
For your second question, you would need to put the code you want to execute into a conditional block:
if(!IsPostback)
{
//execute my code.
}
Upvotes: 2