Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 - is there a way to disable the swipe back and forward functionality in Safari?

Tags:

ios

ios7

safari

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.

But is there a way to disable it for specific pages so as to not have conflicting behavior on the swipe actions?

like image 498
MeghaK Avatar asked Sep 19 '13 08:09

MeghaK


People also ask

How do I stop Safari from swiping back?

Today we want to click on the “More Gestures” tab, then uncheck the box next to “Swipe between pages” to disable the aforementioned feature. Alternatively, if you like this feature but find you often activate it too often, then you can change it from two fingers to three, or you can change it to two or three fingers.

How do I turn off swipe gestures in IOS?

Answer: A: As stated in this article, Switch between apps on iPad - Apple Support. To turn off the multifinger swipe gesture, go to Settings > Home Screen & Dock > Multitasking.


3 Answers

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)

like image 178
Vinzzz Avatar answered Oct 22 '22 22:10

Vinzzz


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

window.history.replaceState(null, null, "#" + url)

instead of pushState or

document.location.hash = url
like image 30
Tom Clarkson Avatar answered Oct 22 '22 21:10

Tom Clarkson


I had to use 2 approaches:

1) CSS only fix for Chrome/Firefox

html, body {
    overscroll-behavior-x: none;
}

2) JavaScript fix for Safari

if (window.safari) {
    history.pushState(null, null, location.href);
    window.onpopstate = function(event) {
        history.go(1);
    };
}

Over time, Safari will implement overscroll-behavior-x and we'll be able to remove the JS hack

like image 42
John Doherty Avatar answered Oct 22 '22 21:10

John Doherty