I would like to execute some code when a user refresh the page but Firefox won't execute my code and nothing work for me. I tried the example below which deoesn't work. I have a global variable called websocket (window.websocket).
window.onunload=function(){
return window.websocket.send(JSON.stringify({type: 'disconnect'}));
};
$(window).on("unload",function() {
return window.websocket.send(JSON.stringify({type: 'disconnect'}));
};
$(window).unload = function() {
return window.websocket.send(JSON.stringify({type: 'disconnect'}));
};
window.addEventListener("unload", function (e) {
window.websocket.send(JSON.stringify({type: 'disconnect'}));
(e || window.event).returnValue = null; //Gecko + IE
return null; //Webkit, Safari, Chrome etc.
});
I've tried some more but nothing work in firefox expect the example below who show me a message come from nowhere and ask me to confirm exit page, but I don't want any confirmation. I really don't understand.
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = "\o/";
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage; //Webkit, Safari, Chrome etc.
});
I don't want any message, just run my code. It's impossible with Firefox?