How to make a download request through a browser?

I have a flash game in which I try to save state when the user closes the browser tab. It uses the following jquery code:

//Called from Flash when window closes
function sendRequest(url, params) {
    $.ajax({
      type: "POST",
      async: false,
      url: url,
      data: params
    })
}

$(window).unload(function() {
  //Make Flash attempt to save the game when the window closes.
  //Flash gets the necessary data and calls sendRequest()
  document["flashGame"].saveBeforeUnload();
});
  • Firefox: working correctly
  • Chrome: works correctly when it reboots , but not when it closes tabs or closes the browser
  • IE (all versions): not working at all

I want it to work correctly in all browsers, but the most important thing is Chrome (many of our users have IE).

Flash correctly calls sendRequest (in all browsers checked with a warning), so I do not believe that problems arose from Flash, but it could be.

+5
source share
2

, .

onbeforeunload Microsoft, . , , (, localStorage). , - jQuery API, :

. , Firefox , , , . , , beforeunload.

, , (, , script), , , , ( ) , onbeforeunload.

onbeforeunload, , "".

+6

window.onbeforeunload. jQueryBug Tracker :

window.onbeforeunload = function() { return "text"; }
+1

All Articles