stopping a page refresh
by gregs on Oct.21, 2005, under JavaScript, browser
I found myself having to trap a user attempting to refresh a page for one of our web apps. After a little bit of digging I stumbled across this solution:
-
<script type="text/javascript">
-
<!--
-
window.onbeforeunload = unloadMess;
-
function unloadMess()
-
{
-
mess = "You are about to refresh the screen and will loose all of your changes.nAre you sure you want to do so?" return mess;
-
}
-
//-->
-
</script>
To use it simply embed or include it into your template
Eventhough the article says this is a IE specific event/feature it also works in FireFox. You should be aware that whenever the user leaves the page, they will be prompted about their impeding data loss, which can get a little tedious while developing.
Again this became a handy feature for our AJAX apps as most of the processing is done in the background without the page reload, a user could accidentally hit the back button and loose where they were at.