So, presumably starting in Firefox> 4, binding a window to a jQuery object before beforeunload no longer works.
What I would like to do is send an AJAX message to delete memcache server data.
When I update the only open tab, I see that the beforeunload event is beforeunload in both firefox and chrome with the following code, as evidenced by the console.log message, "firefox / NON-firefox delete". The problem is that I never see the console.log message "memcache delete" indicating that my server has never seen the $.ajax request.
I understand that working with browning is bad and that there is no difference between what is included in the if and else statements. I am just showing the code for what I tried unsuccessfully in Firefox.
Does anyone have any idea?
$(window).bind('beforeunload', function(){ if(/Firefox[\/\s](\d+)/.test(navigator.userAgent) && new Number(RegExp.$1) >= 4) { console.log('firefox delete'); memcacheDelete(); return null; } else { console.log('NON-firefox delete'); memcacheDelete(); return null; } }); function memcacheDelete() { $.ajax({ url: "/memcache/delete", type: "post", data:{}, success:function(){ console.log('memcache deleted'); }
javascript jquery cross-browser onbeforeunload
tim peterson
source share