Why not register it with both just to be on the safe side? Just have the listener do a check to see if the data's stored yet and exit early.
Here's a quick example using event properties:
window.onunload = window.onbeforeunload = (function(){
var didMyThingYet=false;
return function(){
if (didMyThingYet) return;
didMyThingYet=true;
// do your thing here...
}
}());
Or you could use attachEvent:
(function(){
var didMyThingYet=false;
function listener (){
if (didMyThingYet) return;
didMyThingYet=true;
// do your thing here...
}
window.attachEvent("onbeforeunload", listener);
window.attachEvent("onunload", listener);
}());
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…