Context: We have an immersive game deployed in JS/HTML thanks to GWT. Users have complained about accidentally pressing their Back/Forward mouse buttons while playing, causing them to leave the page unintentionally during action. We want to prevent the default action of these mouse buttons, or come up with some solution that (would normally be annoying and intrusive) which alerts/warns the user with a pop-up stating they are about to leave the game if they hit OK.
Question: How can I prevent the default action of Mouse Button 3 (typically Browser Back button) and Mouse Button 4 (typically Browser Froward Button) throughout the entirety of my webpage?
Potential solution: I saw a similar solution involving addEventListener for 'mousedown'
(ref) and 'mouseup'
(ref) with a subsequent call to a function that triggers event.preventDefault() and event.stopPropagation() perhaps, but am not seeing something similar for the mouse Back and Forward functionality. Also tried something like this, but to no avail (I'm a JS noob).