I might be creepy but I am testing something and I kind of don't understand the purpose of there three events...
so here is my testcode:
<div id="timeBU"></div>
<div id="timeL"></div>
<div id="timeUL"></div>
<div id="text"></div>
<script type="text/javascript">
function loading(message, timeId) {
var secs=0;
var interval = setInterval(function() {
document.getElementById(timeId).innerHTML = secs;
secs++;
},1);
document.getElementById("text").innerHTML += "<br>"+message+"<br>";
}
// first way
window.addEventListener("beforeunload", loading("beforeunload", "timeBU"));
window.addEventListener("load", loading("load", "timeL"));
window.addEventListener("unload", loading("unload", "timeUL"));
// second way
// window.onunload = loading("beforeunload", "timeBU");
// window.onload = loading("load", "timeL");
// window.onbeforeunload = loading("unload", "timeUL");
</script>
it desn't matters I use first way or second way, but anyways I posted both...
What I am saying, that output depend on the order of //first way code or //second way code, which listener is added first, that function's message is displayed first... you can try swapping places... but time is all the same (you can increase interval or alert something for better view), that makes me think that all three events behave same...
Note: I've tested this only for chrome
my extra question is:
How can I differ whether user just opened my site or reloaded?
if you have some kind of advices about my extra question, I would be grateful...