防止意外返回浏览
我有一位客户刚刚购买了 Apple Magic Mouse。我们建立了一个菜谱网站,当她输入菜谱的所有信息时,她感到非常沮丧,然后拿起她的新鼠标,不小心滚动到右侧,它会进行后退浏览,她的所有信息都丢失了。所以她想警告/弹出以防止该页面上发生这种情况。
有什么建议或者给我指出一些可以做到这一点的 JS 吗?
I have a client that just got the Apple Magic Mouse. We built a recipe website and she get very upset when she is inputting all the information for the recipe, then goes for her new mouse and accidentally scrolls to the right and it will do a Back Browse and all her info is lost. So she wants to warning/pop up to prevent this from happening on that page.
Any suggestions or point me to some JS that does this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个基本的“离开前警告”脚本。当用户按下文本区域中的按键时,如果用户要离开页面,系统会通知用户:
或者,您可以在页面加载时将文本字段的内容存储在变量中,然后进行比较。当访问者只需按文本区域中的箭头键而不实际修改它时,这将消除一些混乱。
This is a basic 'warn before leave' script. When the user presses a key in the textarea, the user will be notified if (s)he is about to leave the page:
Alternatively, you can store the contents of the textfield in a variable when the page loads and compare it afterwards. This will take away some confusion when the visitor just press the arrow keys in the textarea without actually modifying it.
您可以连接到 浏览器的 onBeforeUnload 事件,然后显示一条确认消息。
You can hook into the onBeforeUnload event of your browser and then show a confirmation message.