How can one disable a modern browsers default functionality using JQuery or Native JS for going backwards or forwards when scrolling horizontally?
This usually happens when using a trackpad and when scrolled to the end or start of a scrollable div.
Disable Google Chromes Gestures You can disable chromes gestures by going to System Preference > Mouse OR Trackpad > More Gestures > and uncheck Swipe between pages.
If you want to prevent this you have to check your body elements which is larger than the body. It happens when you take a div with some "padding" or "margin" outside ". container" class (twitter bootstrap). So remove all padding and margin outside the container class.
To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML.
To enable horizontal scrolling, we can use the CSS property overflow-x. If we assign the value scroll to the overflow-x property of the container element, the browser will hide horizontally overflowing content and make it accessible via horizontal scrolling.
history.pushState(null, null, location.href);
window.onpopstate = function(event) {
history.go(1);
};
Demo: http://jsfiddle.net/DerekL/RgDBQ/show/
You won't be able to go back to the previous webpage, unless you spam the back button or hold down the back button and choose the previous entry.
Note: onpopstate
(or event onbeforeunload
) doesn't seem to work on iOS.
So I figured since i've created a web app, why not prompt the user for any unsaved changes which will defer the user from loosing any unsaved changes or ending up on the previous or next page in the browser history.
Here is the solution if any one else comes across this problem like I did:
window.onbeforeunload = function(e) {
return 'Ask user a page leaving question here';
};
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