.exitIntercept()

.exitIntercept()

I'd like to submit my very simple solution/replacement for the deprecated .beforeunload() utility.

  1. jQuery.exitIntercept = function(e,msg) {
  2. var message = jQuery.trim(msg);
  3. e = e || window.event;
  4. if (e) {
  5. e.returnValue = message;
  6. }
  7. return message;
  8. }
This small utility is IE/FF/Chrome/Safari safe.

Thanks

Usage: window.onbeforeunload = $.exitIntercept( "You are attempting to leave this page with unsaved changes! If you leave this page without saving your changes, they will be lost!");