Reputation: 332
I need to do an animation when the page refreshes/unloads. I tried <body onunload="myFunction()">
but it does not seem to be working. What should I do?
Upvotes: 3
Views: 7783
Reputation: 28424
In order to call a function before refresh
, you can try the following:
window.addEventListener("beforeunload", function(event) {
myFunction();
});
Upvotes: 2
Reputation: 4572
Try this
window.addEventListener('unload', function(event) {
console.log('hello world');
});
Upvotes: 0