Disable right click context menu on HTML5?

I am trying to disable the right click context menu on HTML5 (Using latest OpenFL 4), but the compiler throws an error when I am trying to use untyped (also reports the wrong line this is occurring at)

#if (js)
	untyped {
		document.oncontextmenu = document.body.oncontextmenu = function() {return false;}
	}
#end

Also tried to use stage.showDefaultContextMenu = false; or stage.addEventListener(MouseEvent.RIGHT_CLICK, function(e:Event){ e.preventDefault(); return false; }); but that seems it works only on flash and causes an error/or it does nothing anywhere else.

Do I need to install something else for untyped to work?

What if you try something like this instead? :

untyped __js__('
	document.oncontextmenu = document.body.oncontextmenu = function(){ return false; }
	')```

The latest Lime and OpenFL development builds now support disabling of the default context menu on HTML5 :success:

stage.showDefaultContextMenu = false;

Thanks :slight_smile:

3 Likes

Ah tried with single quotes and double and still doesn’t seem to work. Also enclosed it in #if js #end of course, not sure what’s the problem.

The latest Lime and OpenFL development builds now support disabling of the default context menu on HTML5

Nice to see that function got some actual use :slight_smile: