I am trying to catch moment when browser is closed by visitor. With window.beforeunload it works perfect for pc users with needed browsers for me. However, I am detecting mobile users with "visibilitychange". It works in some browsers but in safari and chrome with some mobile devices cannot catch when browser closes. After research I couldnt find any way except session. Although I am not sure if this is solution. Is there any way to trigger function when session ends by closing browser ? Or is there better way to handle this problem?
An almost cross-working example with beforeunload:
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = "\o/";
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage; //Webkit, Safari, Chrome
});
more details on : MDN Documentation