Stop context menu from showing

At times you may want to prevent the context menu from showing on your webpage or just an element when users right click on it . This is handy when you’re making games or just using the canvas. Just return false from on the oncontextmenu event.


<div id="mydiv" oncontextmenu="return false;"></div>

This may not work in all browsers. It currently doesn’t work in my Google Chrome browser version 24.0.1312.57 m. You can do it using javascript like this:


var div = document.getElementById('mydiv');

div.oncontextmenu=function(){return false;}

check squirksmode for its compatibility across browsers.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s