Disable Right Click Using jQuery

Their are large number of JavaScript snippets which allows you to disable Right Click on Webpage. But, using jQuery you can perform this task with just few lines of code.

The following jQuery code allows you to quickly disable Right Click on your webpage.

<script>
$(document).ready(function(e) {
    $(document).on('contextmenu',function(e){
		alert("Right click is disable on this website!");
		return false;
	});
});
</script>

 

The above code will disable right click on entire document. To disable right click on specific elements you can use respective selectors.

The following code will disable right click only on images which are being displayed using  tag.

<script>
$(document).ready(function(e) {
    $('img').on('contextmenu',function(e){
		alert("Right Click is not allowed on this website!");
		return false;
	});
});
</script>

 

0 Comments

Leave a Comment.