Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable web page navigation on swipe(back and forward)

On a Windows phone, in IE users can go back and forward by swiping on the screen if the swipe is coming from the edge. This OS level functionality is hampering my webpage's UX.

Is there any js or css which can disable that? Some hack would also do.

A snapshot from windowsphone's website: enter image description here

Here is the link to the reference page: http://www.windowsphone.com/en-in/how-to/wp8/basics/gestures-swipe-pan-and-stretch

Please note that I still need touchaction enabled for horizontal scrolling.

like image 576
Shekhar Joshi Avatar asked Jun 04 '15 06:06

Shekhar Joshi


People also ask

How do I turn off swipe navigation?

Select the Settings menu from the options list. Scroll down to the Continue browser option, and tap on it. Disable the toggle button against the Swipe navigation option to turn OFF.

How do I turn off swipe back to Chrome?

Disable Google Chromes Gestures You can disable chromes gestures by going to System Preference > Mouse OR Trackpad > More Gestures > and uncheck Swipe between pages.

How do I turn off swipe back to Microsoft edge?

In System Preferences go to Trackpad > More Gestures. Then disable "Swipe between pages".

How do I swipe a div in HTML?

The div to swip is id="swiper". JavaScript to Swip(It Works): $(function() { //Enable swiping... $("#swiper").


2 Answers

You Should Try this solution in two way :

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

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

like image 185
Mayur Kukadiya Avatar answered Sep 28 '22 07:09

Mayur Kukadiya


Copy and paste this JavaScript:

var xPos = null; var yPos = null; window.addEventListener( "touchmove", function ( event ) {     var touch = event.originalEvent.touches[ 0 ];     oldX = xPos;     oldY = yPos;     xPos = touch.pageX;     yPos = touch.pageY;     if ( oldX == null && oldY == null ) {         return false;     }     else {         if ( Math.abs( oldX-xPos ) > Math.abs( oldY-yPos ) ) {             event.preventDefault();             return false;         }     } } ); 

If you want it minified, copy and paste this:

var xPos=null;var yPos=null;window.addEventListener("touchmove",function(event){var touch=event.originalEvent.touches[0];oldX=xPos;oldY=yPos;xPos=touch.pageX;yPos=touch.pageY;if(oldX==null && oldY==null){return false;}else{if(Math.abs(oldX-xPos)>Math.abs(oldY-yPos)){event.preventDefault();return false;}}});

like image 32
clickbait Avatar answered Sep 28 '22 07:09

clickbait