I'm detecting window closed this way, and It works but I can't execute a function.
function myFunc(){
alert("byebye");
}
window.onbeforeunload = function (event) {
myFunc(); //Error, it doesn't execute
return "Bye"; //It works, it shows an alert.
};
How can I call myFunc when I'm closing a window/tab?