gregs

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:

CODE:
  1. <script type="text/javascript">
  2. <!--
  3. window.onbeforeunload = unloadMess;
  4. function unloadMess()
  5. {
  6.     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;
  7. }
  8. //-->
  9. </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.


Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!