Detect browser close event or redirection in javascript

Posted by Jpchoudhari under ASP.NET AJAX on 8/9/2012 | Points: 10 | Views : 2655 | Status : [Member] | Replies : 1

How to detect browser window or tab close event or a redirection on client side.

My requirement is, in my project while submitting a form I am uploading files asynchronously and i dont want user to close the tab or move to the different page until the uplaoding is done. I simply want to show a popup to user to wait until all files are uploaded.

How to achive this using javascript or jQuery??

Kind Regards,


Posted by: A4u_6178 on: 10/17/2012 [Member] Starter | Points: 25

You can use the onbeforeunload event like this.

window.onbeforeunload = function (e) {

e = e || window.event;

// For IE and Firefox prior to version 4
if (e) {
e.returnValue = 'Your Pop up Message Goes here';

// For Safari
return 'Your Pop up Message Goes here.;

Thanks & Regards,

Jpchoudhari, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response