Javascript page refreshunload event - Stack Overflow

I need to do an animation when the page refreshesunloads. I tried<body onunload="myFunction(

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?

Share Improve this question asked Jun 28, 2020 at 17:53 kahveciderinkahveciderin 3321 gold badge5 silver badges23 bronze badges 4
  • 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
Add a ment  | 

2 Answers 2

Reset to default 2

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');
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745620568a4636491.html

相关推荐

  • Javascript page refreshunload event - Stack Overflow

    I need to do an animation when the page refreshesunloads. I tried<body onunload="myFunction(

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信