简体   繁体   中英

Javascript page refresh/unload event

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?

In order to call a function before refresh , you can try the following:

window.addEventListener("beforeunload", function(event) {
     myFunction();
});

Try this

 window.addEventListener('unload', function(event) { console.log('hello world'); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM