在离开页面之前询问用户确认的最佳方式 [英] Best way to ask confirmation from user before leaving the page

查看:99
本文介绍了在离开页面之前询问用户确认的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在建立一个注册页面,如果用户离开,我想弹出一个CSS框询问他是否确定。我可以使用确认框来完成这个壮举,但客户说他们太难看了。我尝试过使用unload和beforeunload,但两者都无法阻止页面被重定向。使用那些事件,我返回false,所以也许有一种方法可以取消而不是返回false?

I am currently building a registration page where if the user leaves, I want to pop up a CSS box asking him if he is sure or not. I can accomplish this feat using confirm boxes, but the client says that they are too ugly. I've tried using unload and beforeunload, but both cannot stop the page from being redirected. Using those to events, I return false, so maybe there's a way to cancel other than returning false?

我所拥有的另一个解决方案是将它们重定向到另一个页面有我的弹出窗口,但问题是,如果他们确实想要离开页面,这不是一个错误,他们会失去他们最初试图去的页面。如果我是用户,那会让我感到烦恼。

Another solution that I've had was redirecting them to another page that has my popup, but the problem with that is that if they do want to leave the page, and it wasn't a mistake, they lose the page they were originally trying to go to. If I was a user, that would irritate me.

最后一个解决方案是真正的弹出窗口。我唯一不喜欢的是主要的winow将有他们的目标页面,而pop将有我的页面。在我看来,它看起来不相干。最重要的是,我会担心弹出窗口拦截器。

The last solution was real popup window. The only thing I don't like about that is that the main winow will have their destination page while the pop will have my page. In my opinion it looks disjoint. On top of that, I'd be worried about popup blockers.

只是为了添加每个人的评论。我知道阻止用户退出页面是令人恼火的,我认为不应该这样做。现在我正在使用确认框。发生的事情是它实际上并没有阻止用户离开,如果用户对注册有疑问,客户实际想要做的是提出建议。如果用户处于注册过程的中途并且由于某种原因离开,则客户希望向用户提供免费优惠券到研讨会(该客户正在销售研讨会)以希望说服用户注册。客户的印象是,由于用户已经在表单上,​​他正在考虑注册,因此他正在注册的内容可能是让用户注册的最终推动。理想情况下,我不必阻止用户离开,什么会一样好,而且在我看来更好的是我可以暂停卸载过程。也许睡觉命令?我不需要让用户留在页面上,因为他们将离开去另一个页面。

Just to add to everyones comments. I understand that it is irritating to prevent users from exiting the page, and in my opinion it should not be done. Right now I am using a confirm box at this point. What happens is that it's not actually "preventing" the user from leaving, what the client actually wants to do is make a suggestion if the user is having doubts about registering. If the user is halfway through the registraiton process and leaves for some reason, the client wants to offer the user a free coupon to a seminar (this client is selling seminars) to hopefully persuade the user to register. The client is under the impression that since the user is already on the form, he is thinking of registering, and therefore maybe a seminar of what he is registering for would be the final push to get the user to register. Ideally I don't have to prevent the user from leaving, what would be just as good, and in my opinion better is if I can pause the unload process. Maybe a sleep command? I don't really have to keep the user on the page because either way they will be leaving to go to a different page.

此外,正如人们所说,这个是一个非常可怕的标题,所以如果有人知道一个更好的标题,我真的很感激,如果他们可以将标题更改为没有垃圾邮件邀请的东西。

Also, as people have stated, this is a terriable title, so if someone knows a better one, I'd really appreciate it if they could change the title to something no so spammer inviting.

推荐答案

当我看到阻止用户这个词时,我开始痛苦地哭泣。 从不 阻止用户,只能帮助他们。

As soon as I saw the words "prevent the user" I started to wail in agony. Never prevent the user, only help them.

如果他们看到您的注册页面并且已经开始运行,那是他们的选择。如果他们已经填写了一些数据(因为他们可能会意外导航),请弹出一个javascript确认框,但保留它。如果他们没有触及表单,请不要管它们 - 他们不希望填写您的表单。

If they see your registration page and run off, that's their choice. Pop up a javascript confirm box if they've already filled in some data (because they might be navigating away accidentally) but leave it at that. If they haven't touched the form, leave them alone - they don't want to fill in your form.

查看其他方法吸引用户如果您的表单庞大而且可怕,请将其分解为简单易管理的块或更好的,简化操作以至于用户只在您需要时为您提供数据。例如,在您想要向他们发布内容之前,您可能不需要他们的地址。

Look at other methods of engaging users. If your form is huge and scary, break it into simple manageable chunks or better yet, simplify things so much that the user only gives you data when you need it. For example, you might not need their address until you want to post something to them.

通过将其分成多个部分,您可以使用简单的表单将它们挂钩他们投入了那段时间,他们更有可能继续这个过程。

By breaking it into multiple parts you can hook them with a simple form and once they've invested that time, they'll be more likely to continue the process.

但不要骚扰用户。如果他们不想注册,那么用弹出窗口和jaavscript对话来纠缠他们就会完全将他们赶出网站。

考虑到这一点,假设你只是试图阻止人们填写半填表格,有几种方法可以真正帮助别人:

With that in mind, assuming you're just trying to stop people half-filling-in forms, there are a couple of options to genuinely help people:


  1. 检测表单是否已更改并向他们询问简单的 confirm()消息。

这是全部你可以做。 CSSpop-in无法正常工作,因为你无法在卸载事件中控制*窗口位置。

This is all you can do. A CSS "pop-in" just won't work because you can't control* the window location in the unload event.

*你可以在你的所有页面的链接上放置一个事件监听器来触发检查表单,但这只有在用户点击其中一个链接时才有用。例如,如果用户单击或关闭窗口,则无济于事。你可以同时执行CSS和javascript,但最终会有点混乱。

*You can put an event listener on all your page's links to fire off something to check the form, but this only helps if the user clicks on one of those links. It won't help if, for example, the user clicks back or closes the window. You could do both CSS and javascript but you end up with a bit of a mess.

坚持后面的表单状态场景。

Persist the state of the form behind the scenes.

#1的扩展。而不是与用户争吵,让他们去他们想要的地方,但将表格的内容保存到会话或cookie(如果它适合)并在页面上放一些东西(如页面顶部的SO的橙色提示栏) )提醒他们他们已经开始填写表格并给他们一个回到表格的链接。

An extension to #1. Instead of squabbling with the user, let them go where they want but save the content of the form either to session or cookie (if it'll fit) and put something on the page (like SO's orange prompt bars at the top of the page) that reminds them that they've started filling in a form and gives them a link back to the form.

当他们点击该链接时,你加载数据将cookie(或会话)重新打包到表单中并让它们继续运行。这有明显的好处,让他们在您的网站上做他们喜欢的事情,并保持数据的安全..是。

When they click that link, you load the data out of the cookie (or session) back into the form and let them carry on. This has the clear benefit of letting them do what they like on your site and keeps the data safe.. ish.

如果他们没有回来并且他们的cookie /会话到期,那就是他们的错。你只能把马带到水里。强迫它喝酒不是你的工作。

If they don't come back and their cookie/session expire, that's their fault. You can only lead a horse to water. It's not your job to force it to drink.

这篇关于在离开页面之前询问用户确认的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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