Disable Right Click – One line script for all browsers

A single attribute which helps us to disable Right Click Event and this script will work for all the browsers including IE Old Versions.

Here you are:

oncontextmenu="return false;"

Add this attribute in the <body> tag of your website pages.

Example:

<html>
<head>
</head>
<body oncontextmenu="return false;">
<a href="http://www.agurchand.com">Agurchand</a>
</body>

 

If you have already own a website which has 1000’s of pages, then use this method to add the attribute using jQuery:

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
	$(function(){
		$('body').attr('oncontextmenu','return false');
	});
</script>
</head>
<body>
<a href="http://www.agurchand.com">Agurchand</a>
</body>
</html>

Put this code where you call a JavaScript in all of your pages:

$('body').attr('oncontextmenu','return false');

 

I hope this would have helped you. Thanks!

 

2 thoughts on “Disable Right Click – One line script for all browsers”

Leave a Comment

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

Scroll to Top