gregs

helping me remember what I figure out

stopping a page refresh

| 0 comments

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

Required fields are marked *.

*