Can I prevent window.onbeforeunload from being called when doing an AJAX call

Posted by Paul on Stack Overflow See other posts from Stack Overflow or by Paul
Published on 2009-02-11T16:45:11Z Indexed on 2010/03/24 13:53 UTC
Read the original article Hit count: 760

Filed under:
|
|

I have an AJAX-based grid control.

We hook into the window.onbeforeunload event to check if they have unsaved data and if so present them with a message "Are you sure you want to navigate away...you have unsaved data...".

All this is good.

But AJAX calls also trigger window.onbeforeunload and so if the grid has unsaved data and we make an AJAX call (such as to delete a row in another grid) the user gets the "Are you sure you want to navigate away...you have unsaved data..." message which is not good.

Is it possible to suppress the onbeforeunload event for AJAX calls? Or is it possible to detect that a call is an AJAX call? Otherwise we'll have to get hacking!

Thanks

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about AJAX