Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This will take a timestamp of when __doPostBack was called and then carry out the default behavior. </p> <p>The onbeforeunload event will only show your custom message when the difference between it's timestamp and the latest __doPostBack timestamp is greater than allowedWaitTime.</p> <p>Usage: include it anywhere in your page.</p> <h1>Update:</h1> <p>This will now handle WebForm_DoPostBackWithOptions also</p> <pre><code>(function ($) { if (typeof $ !== 'function') { throw new Error('jQuery required'); } /* The time in milliseconds to allow between a __doPostBack call and showing the onbeforeunload message. */ var allowedWaitTime = 100, timeStamp = new Date().getTime(), // Each function to override baseFuncs = { __doPostBack: this.__doPostBack, WebForm_DoPostBackWithOptions: this.WebForm_DoPostBackWithOptions }; // Set timeStamp when each baseFunc is called for (var baseFunc in baseFuncs) { (function (func) { this[func] = function () { var baseFunc = baseFuncs[func]; timeStamp = new Date().getTime(); if (typeof baseFunc === 'function') { baseFunc.apply(arguments.callee, arguments); } } })(baseFunc); } /* Form submit buttons don't call __doPostBack so we'll set timeStamp manually on click. */ $('input[type="submit"]').click(function () { timeStamp = new Date().getTime(); }); $(this).on('beforeunload', function (e) { // Only return string if allowedWaitTime has elapsed if (e.timeStamp - timeStamp &gt; allowedWaitTime) { return 'message'; } }); }).call(window, jQuery); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload