Browser waits for ajax call to complete even after abort has been called (jQuery)

Thank you for your replies! It turns out I was completely wrong about this being a browser issue – the problem was on the server. ASP.NET serializes requests of the same session that require session state, so in this case, the next page didn’t begin processing on the server until those ajax-initiated requests completed. Unfortunately, … Read more

Using onbeforeunload without dialog?

From the Mozilla Developer Network page: When this event returns a non-void value, the user is prompted to confirm the page unload. This means the return value of the handler must be undefined (not ”, false, or null) in order to avoid triggering the confirmation prompt. window.onbeforeunload = function() { $.post(“track.php”, { … }); return … Read more

Way to know if user clicked Cancel on a Javascript onbeforeunload Dialog?

You can do it like this: $(function() { $(window).bind(‘beforeunload’, function() { setTimeout(function() { setTimeout(function() { $(document.body).css(‘background-color’, ‘red’); }, 1000); },1); return ‘are you sure’; }); }); The code within the first setTimeout method has a delay of 1ms. This is just to add the function into the UI queue. Since setTimeout runs asynchronously the Javascript … Read more

Crossbrowser onbeforeunload?

I found a workaround for Firefox with setTimeout function because it does not have the same behaviour as other web browsers. window.onbeforeunload = function (e) { var message = “Are you sure ?”; var firefox = /Firefox[\/\s](\d+)/.test(navigator.userAgent); if (firefox) { //Add custom dialog //Firefox does not accept window.showModalDialog(), window.alert(), window.confirm(), and window.prompt() furthermore var dialog … Read more

window.onbeforeunload – Only show warning when not submitting form [duplicate]

Using the form’s submit event to set a flag might work for you. var formHasChanged = false; var submitted = false; $(document).on(‘change’, ‘form.confirm-navigation-form input, form.confirm-navigation-form select, form.confirm-navigation-form textarea’, function (e) { formHasChanged = true; }); $(document).ready(function () { window.onbeforeunload = function (e) { if (formHasChanged && !submitted) { var message = “You have not saved … Read more