Search code examples
javascriptjqueryfirefoxbrowserwebkit

How to prevent a browser from going back/forward in history when scrolling horizontally?


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.


Solution

  • 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';
    };