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); }
var some_ajax_data; window.onbeforeunload = function() { navigator.sendbeacon('/data.php', some_ajax_data); };
Comments
Post a Comment