Navigate Away Page Alert


Hi Friends,

Have you ever seen this message on webpages,

“Are you sure you want to navigate away from this page?
Press OK to continue, or Cancel to stay on the current page.”

The best example to see this message is when you are composing a email in Gmail and then when you try to close Gmail without sending or saving email, Gmail will prompt this message.

You can use this message on your webpage where you doing some process in backend, it may be an AJAX request as well.

So to implement this, Javascript as already a built in function, may be most of us don’t know about this

window.onbeforeunload = function() { return "Are you sure you want to leave?"; }

Try this!

cheers,
JT

Advertisements