I have a form where the input fields are saved onChange. In Firefox (5) this works even when the window is closed, but for Chrome and IE it doesn\'t and I need
You have to return from the onbeforeunload:
window.onbeforeunload = function() {
saveFormData();
return null;
}
function saveFormData() {
console.log('saved');
}
UPDATE
as per comments, alert does not seem to be working on newer versions anymore, anything else goes :)
FROM MDN
Since 25 May 2011, the HTML5 specification states that calls to
window.showModalDialog(),window.alert(),window.confirm(), andwindow.prompt()methods may be ignored during this event.
It is also suggested to use this through the addEventListener interface:
You can and should handle this event through
window.addEventListener()and thebeforeunloadevent.
The updated code will now look like this:
window.addEventListener("beforeunload", function (e) {
saveFormData();
(e || window.event).returnValue = null;
return null;
});