javascript - Jquery - Post beforeunload -
i want post data before unload (just before visitor closes page). unload may vary on different browsers, have done following script;
$(document).ready(function(){ var runme = true; $(window).bind('beforeunload', function () { if(runme){ if ($("#benyaziyormuyum").val()=="evet") { $.post("yazmabirak.php", { karsidaki: "exited", }); } runme=false; } }); $(window).unload(function () { if(runme){ $.post("yazmabirak.php", { karsidaki: "exited", }); runme=false; } });
it works on browsers, except chrome. question is, before unload function should used make work on chrome ?
are sure isn't getting called?
$.post asynchronous call , have nothing prevents browser continuing on after $.post().
you need make synchronous using $.ajax() can set async: false
Comments
Post a Comment