停止向后/向前两次手指滑动 [英] Stop chrome back/forward two finger swipe

查看:116
本文介绍了停止向后/向前两次手指滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想停用导致Chrome返回或前进的双指滑动。
我有一个网站,用户可能会失去他的工作进度,如果他没有特别保存。

I want to disable the two finger swipe that causes Chrome going back or forward. I have a website where the user might lose progress on his work if he doesn't specifically saves.

我曾尝试使用 window.onbeforeunload 但这似乎不工作,如果我有在网址哈希(后退将改变www.example.com/work/#step1#unsaved www.example.com/work /#step0),并且该事件似乎没有触发。

I have tried using window.onbeforeunload but that doesn't seem to work if I have hashes in the url (back forward would change between www.example.com/work/#step1#unsaved www.example.com/work/#step0) and the event doesn't seem to trigger.

我正要切换到另一个解决方案,但今天我注意到,在Google文档中,它完全禁用。他们是如何实现这一目标的?

I was about to switch to another solution but today I noticed that in Google Docs it's completely disabled. How did they achieve that?

推荐答案

你在错误的层面上看问题。 OnBeforeUnload只是没有被触发,因为没有任何东西从浏览器的角度被卸载。因此,你直言不讳地实现了版本控制的错误机制 - 片段是针对页面状态的,而不是现在使用的文档状态。

You're looking at the problem at the wrong level. OnBeforeUnload is simply not triggered because there is nothing being unloaded from the browsers perspective. Therefore you have, quite bluntly, implemented the wrong mechanism for versioning - fragments are for page states, not document states as you are using it now.

如果你坚持维护通过散列碎片状态,您需要使用另一种机制来防止页面状态改变。由于目前所有浏览器都支持LocalStorage,因此我会使用它。而且,在这个过程中,将所有文档状态数据放在那里,而不是放在URL中,因为这就是Google Docs的功能,这就是为什么他们没有这个问题。

If you insist on maintaining state through hash fragments you need to use another mechanism to guard against page state changing. Since all current browsers support LocalStorage I'd use that. And well, while at it, put all the document state data there instead of in the URL, since that is how Google Docs does it and that is why they don't have this issue.

这篇关于停止向后/向前两次手指滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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