1

I need to fire some functionality from javascript when a user has finished editing a page and saves it or leaves the editing mode.

Is there a possibility to catch the event?

Florian Leitgeb
  • 748
  • 1
  • 11
  • 22

1 Answers1

1

Use window.onbeforeunload in edit mode to perform all your operations. Here is how you check edit/display mode

    window.onbeforeunload = function (e) {
    var message = "Your confirmation message goes here.",
     e = e || window.event;
     // For IE and Firefox
     if (e) {
        e.returnValue = message;
     }

      // For Safari
      return message;
};
Falak Mahmood
  • 17,298
  • 2
  • 40
  • 67
  • Can I determine from the returnValue if the site was really saved on the server? Because as I understand, this event is always fired when user leaves edit mode, regardless if he saved the site or discarded check out. – Florian Leitgeb Jun 19 '15 at 10:12
  • Unfortunately it is also not possible to gather user information in the on onbeforeunload, because you can not fire alerts or confirm messages. – Florian Leitgeb Jun 24 '15 at 12:34