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?
There isn't a Safari-specific setting for this. To disable it in Safari, you will need to disable the swiping gestures system-wide.
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.
To turn off the swipe keyboard feature on your iPhone: Open “Settings” > “General”. Tap on “Keyboard”. Scroll down and toggle off “Slide to Type”.
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.
Apple provided these guidelines after iOS9.
The guide lets you disable
Scrolling
function touchMove(event) {
// Prevent scrolling on this element
event.preventDefault();
...
}
Pinch and Zoom
function gestureChange(event) {
// Disable browser zoom
event.preventDefault();
...
}
You can identify a swipe gesture as follows:
The full guide is poster here.
Let me know if you need more help.
Nitin, Defuzed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With