How to Disable right click using JavaScript

Some time your page contains sensitive data for example your page contains images and you don’t want user download those images by right clicking, in this situation you need to disable right click. However many developers are saying “Don’t do it” because we can’t  prevent users for this!

However if you still want to disable right click you can use below snippet of JavaScript.

<script type="text/javascript">
	document.oncontextmenu = new Function("return false");

Or simply you can use JavaScript code on context menu event of body tag.

<body oncontextmenu="return false">

Leave a Reply

Your email address will not be published. Required fields are marked *