I don't know if there is a direct way to do this, but you could always emulate the browser's confirmation box yourself. Here's a simple function I cooked up based on the specs at MSDN:
function triggerBeforeUnload() {
var event = {};
handler(event);
if (typeof event.returnValue == 'undefined' ||
confirm('Are you sure you want to navigate away from this page?
' + event.returnValue + '
Press OK to continue, or Cancel to stay on the current page.')) {
// Continue with page unload
} else {
// Cancel page unload
}
}
Edit: In jquery.formobserver.js
, right after the definition of function beforeunload(e) { ... }
, add this line:
handler = beforeunload;
Note the change in the original code: window.onbeforeunload
has been replaced by handler
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…