How to block right click in browser window

In some web app we want to cancel the usual window’s right click context menu and we either want to show our own custom menu or we just want to disable right click functionality for any purpose.

Here is the solution..

Using javascript

document.body.setAttribute(‘oncontextmenu’, function() { return false; });

In html

<body oncontextmenu=’”function() { return false; }”>

..

</body>

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