javascript - run a function before Firefox close the window -


this first topic here! so, i'm trying run ajax function before firefox's window close, code works when close tab, window not. how can this?

detail: firefox don't run function when window closed , if possible without use jquery.

window.onload = function(){     window.addeventlistener('beforeunload',function(event){         var ajax = new xmlhttprequest();         ajax.open("post","index.php",true);         ajax.send();     }, false); } 

try navigator.sendbeacon

var some_ajax_data;  window.onbeforeunload = function() {   navigator.sendbeacon('/data.php', some_ajax_data); }; 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -