You should write it like this:
window.onunload = goodBye;
Also, you might consider using the onbeforeunload event in some browsers:
window.onbeforeunload = goodBye;
When you write window.onunload = goodBye();
you assign whatever handler that is returned from goodBye
to the unload
event. Since nothing is returned, there will be no event handler. You need to reference the function instead: window.onunload = goodBye;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…