[Pro] Jquery warning or force previous page to refresh when using browser back butto

Hi

I searched the net, found different solutions that do not work.

I am on a build (EE) with several forms that has to be filled in after one another. When a visitor would click on the browser back button, the chain is broken.

Does any of you know of a JQuery way to show a warning, or -even better- force refresh the previous page?

I certainly do not want to mess with the visitors browser, but I need to have a bit of control…:wink:


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You want to hook the ‘onbeforeunload’ event. In Prototype you would do this:

Event.observe(window, 'beforeunload', function(evt){
    return confirm('You have entered form data without saving it. Are you sure you want to leave this page?');
});

I’m not sure how you would write this in jQuery or vanilla JavaScript, so you’ll have to hunt around if you want to do this there. But this should show you the basic idea.

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Walther

I found a script that seems to work. But when I checked in Safari, the page seemed to load in infinity when canceling the leaving of the page. Felt not good. Firefox acted normal.

For me hard to know why this happens, and even harder how to trust those script from the net.





<script type="text/javascript"> window.onbeforeunload = function(e) {
return 'You have unsaved changes. If you leave the page these changes will be lost.';
};
</script>

dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options