问题
I use the follow function to detect window close event to perform some cleanup tasks:
window.addEventListener('beforeunload', function(e) {
console.log("window close");
// perform cleanup
}
Unfortunately I also get this event during meteor auto-reload (for ex. when there is change in code) during which I don't want to perform cleanup.
How do I differentiate between the two situations? (I have a peculiar usecase where I have to differentiate between the two situations)
回答1:
You would have to tap into the Meteor onmigrate
api which could help you distuinguish the two:
Client side code:
var hotcodepush = false;
Reload._onMigrate(function () {
hotcodepush = true;
return [true];
});
window.addEventListener('beforeunload', function(e) {
if(!hotcodepush) console.log("window close");
if(hotcodepush) console.log("Hot code reload");
}
回答2:
Without knowing meteor. I would try to find the point which is executed just before the auto-update (if possible) and define a abort event|variable|... I hope this helps
来源:https://stackoverflow.com/questions/21940888/beforeunload-event-during-window-close-vs-meteor-auto-reload