Skip to content Skip to sidebar Skip to footer

Unload Event In IE10, No Form Data

I have window.unload hooked to save my form data in emergencies when the user just closes their browser. I send this using ajax via POST. This works in IE9, Chrome etc, but not in

Solution 1:

I assume, you are using code like this:

<html>
   ...
   <body onunload="inOnUnload();">
      ...

with an inOnUnload()-function being defined like the following:

function inOnUnload() {
   xmlhttp.open("POST", "http://some-location", /*async*/ true);
   http.send(request);
}

The problem with this in IE10 is that it seems to cancel the request, after the document has finally been unloaded. This happens before the form data had a chance to leaf the client. To send data in onunload events in IE10, you must use the async = false parameter in XMLHttpRequest.open(...).

The following works fine for me:

function inOnUnload() {
   xmlhttp.open("POST", "http://some-location", /*async*/ /*!!!*/ false);
   http.send(request);
}

Post a Comment for "Unload Event In IE10, No Form Data"