Search Unity

Right clicks in the game causes browser to go back

Discussion in 'Web' started by nsmith1024, Jul 14, 2019.

  1. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    Hello,

    I have a WebGL game where the user holds down the right mouse to move the camera.

    This works fine in Chrome, but on Opera sometimes it causes the browser to go back to the previous page exiting the game page by accident.

    Im not sure its cause by a double mouse click or a right click but it seems to happen randomly with Opera after like a minute of game play and various mouse clicks it causes the browser to exit the game page and go back to the previous page, as if i clicked the browser back button.

    Here is a section of the index.html code, anybody knows how to fix it? Thanks!

    Code (JavaScript):
    1.     <script>
    2.         var gameInstance = UnityLoader.instantiate("gameContainer", "Build/htdocs.json", {
    3.             onProgress: UnityProgress, Module: {
    4.                 onRuntimeInitialized: function () {
    5.                     this.canvas.addEventListener("contextmenu", function (e) {
    6.                         e.preventDefault();
    7.                     });
    8.                 },
    9.             }
    10.         });
    11.     </script>
     
    Last edited: Jul 14, 2019
  2. UDN_08a62c30-cdb1-4e59-bb48-acda29f9e582

    UDN_08a62c30-cdb1-4e59-bb48-acda29f9e582

    Joined:
    Jun 19, 2018
    Posts:
    23
    In opera there is mouse gestures. Holding right button and moving left cause "Go back one page"
     
  3. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    Wow, Yes you are exactly right, this is what is causing the problem, thanks so much, i have to figure out how to block it from within the unity program, or javascript.