I can't trigger the unload event in Chrome

前端 未结 4 917
时光取名叫无心
时光取名叫无心 2020-12-17 18:58

This code runs fine on Firefox, but I can\'t make the unload event work on Chrome anymore. Did Chrome stop supporting the unload event?

This is my c

4条回答
  •  误落风尘
    2020-12-17 19:06

    From what I've read it seems Chrome blocks alerts once that event has been triggered. You can run some functions, however, just not anything that interacts with the user it seems.

    From window.onbeforeunload in Chrome: what is the most recent fix?, it seems, if all you want to do is pop up a confirmation message, you have to do it by returning a string with the message from the function you set as the callback.

    window.onbeforeunload = function() {
        // Some wrap up code (no alerts, confirms, redirects, etc)
        return 'My confirmation messsage'; 
    }
    

    The text "My confirmation message" will then show up in a confirmation dialogue of Chrome's choosing. Firefox documents this behaviour here.

提交回复
热议问题