Disable Right-Click menu in HTML5



  • Hey guys! I'm making a game that should support both Desktop and HTML5, and it uses right-click as a command, but on HTML5 the context menu also comes up. I've been searching for a while but I couldn't find anything. Is there a way to disable the right-click context menu in HTML5?



  • Ok guys, I managed to solve my problem. I will post the solution so that other people can get help without making new threads.

    It was really a simple thing that I didn't think about because I'm not a webdev.
    I went in the export folder and I opened the (game).js file, under ApplicationMain.create = function() { I added document.oncontextmenu = document.body.oncontextmenu = function() {return false;}
    Now it looks like this:

    ...
    ApplicationMain.create = function() {
    	document.oncontextmenu = document.body.oncontextmenu = function() {return false;}
    	var app = new openfl_display_Application();
    	app.create(ApplicationMain.config);
    ...
    

    The only problem is that every time you make a new build you will have to edit the file again, but it's not that big of a problem if you only do it when you have to release the game to playtesters or to the public.

    Hope this will help!


  • administrators

    No need to fiddle with the generated code, you can do this from Haxe via untyped:

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


  • Oh that is even better! Thanks a lot!


Log in to reply