Sorry, my v4.0 didn't check if the form was being submitted... Here is
the updated code. If you test this in Firefox (windows 2), you'll see
what I want to achieve :)
In IE the returnValue of the event doesn't get sent (so in the
confirmation window it just writes "false" ).
In opera it doesn't work. Even though, if I can get it to work in IE /
FF, I'll be happy :)
Here's the script v4.1
<script type="text/javascript">
var FormWatch4 = Class.create();
FormWatch4.prototype = {
initialize : function(form, options) {
this.submitted = false;
this.form = $(form);
// Let's serialize this.form and store it...
this.formcontents = $(form).serialize();
// Observe beforeunload event...
Event.observe(this.form, 'submit', function() {this.submitted =
true; }.bind(this));
Event.observe(window, 'beforeunload',
this.confirmExit.bind(this));
},
confirmExit : function(ev) {
this.newcontents = this.form.serialize();
if ((this.formcontents != this.newcontents) && !
(this.submitted)) {
ev.returnValue = "This is my error string";
return Event.stop(ev);
}
}
}
</script>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---