Disable context menu in Firefox

Get help using Construct 2

Post » Mon Sep 07, 2015 5:33 pm

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?
B
10
S
3
Posts: 28
Reputation: 756

Post » Mon Sep 07, 2015 6:52 pm

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>
B
8
S
4
Posts: 131
Reputation: 1,205

Post » Mon Sep 07, 2015 10:05 pm

you can use Browser object...

On start of layout....Browser Execute Javacript
Code: Select all
"$('body').attr('oncontextmenu','return false;')
function click(e)
{
if (e.button==2||e.button==3)
{
e.preventDefault();
e.stopPropagation();
return false;
}
}

document.onclick=click;"



JQuery vs. JavaScript: What’s the Difference Anyway?
Image
B
64
S
23
G
7
Posts: 1,481
Reputation: 10,823

Post » Tue Sep 08, 2015 10:26 am

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?
B
10
S
3
Posts: 28
Reputation: 756

Post » Tue Sep 08, 2015 4:30 pm

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.
B
10
S
3
Posts: 28
Reputation: 756


Return to How do I....?

Who is online

Users browsing this forum: apalm1341, blissfulwizard and 15 guests