Disable context menu in Firefox

0 favourites
  • 5 posts
From the Asset Store
ready made menu you can download this one or just follow my tutorial to make it yourself
  • Hey,

    I have a game that makes excessive use of right click and has a bunch of transparent UI (text) elements on the screen. Now, those "Text" objects are really stylized Textbox objects. I use the Advanced Textbox plugin + some extra CSS. This is because making Text look the same on all browsers is a nightmare, and Spritefont isn't flexible enough for my needs.

    I know C2 prevents context menu from opening on right click, but that's not the case with Textboxes apparently. I've added a little Javascript using the Browser object:

    document.oncontextmenu = document.body.oncontextmenu = function() {return false;}

    Works fine in Chrome and Opera, but NOT IN FREAKING FIREFOX.

    How do I disable context menu from appearing in Firefox when right clicking a Textbox?

  • Had a similar problem yesterday

    Didn't test with textboxes but I was unable to block shift + right click contextual menu until I used this :

    Maybe it can work for you too ? It worked for me w/ Firefox 40 (the latest)

    It's using Jquery so I put it just after the jQuery embed line. (line 82 of my index.html)

    <script>$('body').attr('oncontextmenu','return false;')

    function click(e)

    {

    if (e.button==2||e.button==3)

    {

    e.preventDefault();

    e.stopPropagation();

    return false;

    }

    }

    document.onclick=click;

    </script>

  • you can use Browser object...

    On start of layout....Browser Execute Javacript

    "$('body').attr('oncontextmenu','return false;') 
    function click(e)
    {
    if (e.button==2||e.button==3)
    {
    e.preventDefault();
    e.stopPropagation();
    return false;
    }
    }
    
    document.onclick=click;"[/code:253497on]
    
    [url=https://blog.udemy.com/jquery-vs-javascript/]JQuery vs. JavaScript: What’s the Difference Anyway?[/url]
  • Thanks for the replies, but still not working. Context menu still appears in Firefox when I right click a Textbox.

    I don't mind if Shift + RMB brings up the context menu, as I'm not trying to defend against content theft, since this is not the right way to do it. It's easy to work around it. I'm talking about simple right click on a Textbox. I use CSS user-select: none, but that only prevents highlighting the text.

    I've tried a couple of other scripts as well, none of them seem to work. And yes, I'm using the latest Firefox.

    Other ideas?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Okay, so I've learned that contextmenu events don't work in Firefox on disabled elements. My Textboxes must be disabled for them to look like text, because otherwise there's a caret and in-game RMB events don't fire.

    I'm gonna wait a little more, maybe somebody knows the magic trick, but I can foresee an increase in my memory usage because of Spritefonts... I use different font faces, styles, sizes, colors, etc. Shit.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)