On 14 nov, 15:32, Michael Peters <[EMAIL PROTECTED]> wrote:
> ditman wrote:
> > I've tried to implement 2 suggestions that you have made here...
>
> May I suggest a 3rd? When your page is loaded serialize the form into a JSON
> string and store the results. Then in your unload handler serialize the form
> again. If the 2nd serialized string matches the first then nothing has changed
> so you ignore it. If it has, then something has changed so you warn the user.
>

Cool solution, this simplifies my first version a lot, but still has
the following problems:
 - Doesn't work with Opera
 - I can't customize the returnValue of the event in IE :(

Here it goes:

<script type="text/javascript">
  var FormWatch4 = Class.create();
  FormWatch4.prototype = {
    initialize : function(form, options) {
    this.form = $(form);
    // Lets serialize this.form and store it...
    this.formcontents = $(form).serialize();
    // Observe beforeunload event...
    Event.observe(window, 'beforeunload',
this.confirmExit.bind(this));
  },
  confirmExit : function(ev) {
    this.newcontents = this.form.serialize();
    if (this.formcontents != this.newcontents) {
      return Event.stop(ev);
    }
  }
}
</script>

How can I fix that code to modify the returnValue of "ev" in
confirmExit ? ev.returnValue = "My Error String" works in FF but not
in IE.

Then... How can I make it work in Opera?? :D

Thanks! :)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to