[英]Javascript page refresh/unload event
I need to do an animation when the page refreshes/unloads.当页面刷新/卸载时,我需要执行 animation。 I tried
<body onunload="myFunction()">
but it does not seem to be working.我试过
<body onunload="myFunction()">
但它似乎不起作用。 What should I do?我应该怎么办?
In order to call a function before refresh
, you can try the following:为了在
refresh
之前调用 function ,您可以尝试以下操作:
window.addEventListener("beforeunload", function(event) {
myFunction();
});
Try this尝试这个
window.addEventListener('unload', function(event) { console.log('hello world'); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.