在用户点击浏览器后退按钮时提醒用户-有充分的理由 [英] Alert user when they hit the browser back button - with good reason

查看:92
本文介绍了在用户点击浏览器后退按钮时提醒用户-有充分的理由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是禁忌的边界,请不要回复您永远不要这样做"等.

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 to using the browser's back and forward buttons that they use those instead of the "Back" and "Next" buttons on the form wizard. If they hit the browser's back button, they will lose all of their form data (which is a pain in the ass, since the form is so long).

是否可以显示警报,提示何时会有带我离开这里"按钮和取消"按钮,因此如果他们单击取消",则会取消后退"按钮的功能?

Is it possible to display an alert that when will have a "take me out of here" button and a "cancel" button, so if they hit cancel it will cancel the function of the back button?

推荐答案

您应该从onbeforeunload事件中返回一条消息,如下所示:

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.

这篇关于在用户点击浏览器后退按钮时提醒用户-有充分的理由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆