Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  100] [ 6]  / answers: 1 / hits: 19898  / 6 Years ago, thu, may 3, 2018, 12:00:00

Swiping from the left and right edges of my iPad's Safari browser, moves between the currently open web pages. Is there any way to prevent it?



I have tried to add touchstart and touchmove handlers on the edge of the page that stopPropagation and preventDefault, but they seem to have no effect, nor does touch-action CSS.



A similar question was asked in 2014 with replies to the negative:
iOS 7 - is there a way to disable the swipe back and forward functionality in Safari?



Is there a workround now in 2018?


More From » html

 Answers
12

In iOS 13.4+ you can now preventDefault on touchstart



Let's say we have a <div class=block-swipe-nav> on the page that spans the entire width of the viewport and we want to prevent swipe navigation on that element.



const element = document.querySelector('.block-swipe-nav');

element.addEventListener('touchstart', (e) => {

// is not near edge of view, exit
if (e.pageX > 10 && e.pageX < window.innerWidth - 10) return;

// prevent swipe to navigate gesture
e.preventDefault();
});


I've written a short article on blocking swipe with some additional information.


[#54517] Sunday, April 29, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jimmieo

Total Points: 515
Total Questions: 102
Total Answers: 110

Location: Kazakhstan
Member since Mon, Sep 26, 2022
2 Years ago
;