iOS 7 - 有没有办法在 Safari 中禁用前后滑动功能?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18889666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS 7 - is there a way to disable the swipe back and forward functionality in Safari?
提问by MeghaK
For some web pages we use the swipe left and right functionality of iPhone to pull up the menus. Now with iOS7, they have introduced the ability to go back and forward to previous and next pages of browser history on swipe left and right motions.
对于某些网页,我们使用 iPhone 的左右滑动功能来拉出菜单。现在在 iOS7 中,他们引入了通过向左和向右滑动来返回和前进浏览器历史记录的上一页和下一页的功能。
But is there a way to disable it for specific pages so as to not have conflicting behavior on the swipe actions?
但是有没有办法为特定页面禁用它,以便在滑动操作上不会出现冲突行为?
回答by Vinzzz
No, this is done at the OS level, and webpage doesn't get any callback
不,这是在操作系统级别完成的,网页没有任何回调
See this summary of safari changes in iOS7 that might cause problems to your website(including this swipe gesture)
查看iOS7 中可能导致网站出现问题的 safari 更改摘要(包括此滑动手势)
回答by Tom Clarkson
You can't disable it directly, but the native swipe back only happens if there is something in the browser history.
您不能直接禁用它,但是只有在浏览器历史记录中有某些内容时才会发生本机向后滑动。
It won't work in every case, but if you have a single page web app opened in a new tab, you can prevent it from adding to the history by using
它不会在所有情况下都有效,但是如果您在新选项卡中打开了一个单页 Web 应用程序,则可以使用以下命令阻止它添加到历史记录中
window.history.replaceState(null, null, "#" + url)
instead of pushState or
而不是 pushState 或
document.location.hash = url
回答by John Doherty
I had to use 2 approaches:
我不得不使用两种方法:
1) CSS only fix for Chrome/Firefox
1) CSS 仅适用于 Chrome/Firefox
html, body {
overscroll-behavior-x: none;
}
2) JavaScript fix for Safari
2) Safari 的 JavaScript 修复
if (window.safari) {
history.pushState(null, null, location.href);
window.onpopstate = function(event) {
history.go(1);
};
}
Over time, Safari will implement overscroll-behavior-xand we'll be able to remove the JS hack
随着时间的推移,Safari 将实现overscroll-behavior-x,我们将能够删除 JS hack