Alert user when they hit the browser back button - with good reason

前端 未结 2 2068
北荒
北荒 2021-02-20 18:04

I know this borders on the taboo here, and please don\'t reply with \"you should never do this\", etc.

I have a very long form in a wizard, and some users are too used t

2条回答
  •  余生分开走
    2021-02-20 18:27

    You should return a message from the onbeforeunload event, like this:

    window.onbeforeunload = function() {
        return "Leaving this page will reset the wizard";
    };
    

    Note that this event will fire when the user leaves the page for any reason, even after your wizard finishes.
    You should set a flag when the wizard finishes and not return a message.

提交回复
热议问题