admin管理员组文章数量:1025208
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?
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?
-
shouldnt it be
onbeforeunload
– john Smith Commented Jun 28, 2020 at 17:56 - your code isn't guaranteed to run with the unload events. – Daniel A. White Commented Jun 28, 2020 at 17:57
- @johnSmith I dont think so: this and this – kahveciderin Commented Jun 28, 2020 at 17:57
- I'm pretty sure that's no longer possible. – D. Pardal Commented Jun 28, 2020 at 18:07
2 Answers
Reset to default 2In 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');
});
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?
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?
-
shouldnt it be
onbeforeunload
– john Smith Commented Jun 28, 2020 at 17:56 - your code isn't guaranteed to run with the unload events. – Daniel A. White Commented Jun 28, 2020 at 17:57
- @johnSmith I dont think so: this and this – kahveciderin Commented Jun 28, 2020 at 17:57
- I'm pretty sure that's no longer possible. – D. Pardal Commented Jun 28, 2020 at 18:07
2 Answers
Reset to default 2In 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');
});
本文标签: Javascript page refreshunload eventStack Overflow
版权声明:本文标题:Javascript page refreshunload event - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745620566a2159546.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论