Disable Mouse Right Click Using Jquery: Hi Friends, Today i will tell you how to disable right click of the mouse on your web page using jquery. As we know some of the guys are taking advantage to steel your code and hack your website. When anyone using right click inspect element, he/she knows about your static code. It will create problem some times. To overcome the problem of hacking website and steeling code, you can prevent the user to use right click of the mouse.
When we talk about preventing right click by the user and make your website safe from the spammer and hacker. Today i will tell you 3 different disable right click using jquery. These ways are
To disable the right click on certain elements, you have to put the class or id in the selector. After adding the jquery code, if anyone tries to use right click, alert comes “Right Click has been disabled”. You can change it as per your requirement.
<script> $(function() { // Right Click disabled on some part of your webpage only $('#disableMouseRightClick').on("contextmenu",function(e){ alert('right click has been disabled'); return false; }); }); </script>
You can see the live demo by clicking on the below button or you can also download the code Anytime.
If you want to prevent mouse right click of the entire document then you can use below code. When anyone try to right click, alert will show everytime. It is the best practice of website to protect from spammers and hackers
<script type="text/javascript"> // Right Click disabled on Complete webpage webpage only $(document).on("contextmenu",function(e){ alert('right click has been disabled'); return false; }); </script>
You can see the live demo by clicking on the below button or you can also download the code Anytime.
If you want no one can download your images by right click and choose the option of save images to save the image then you can use below code. When any user try to right click, it shows nothing
<script type="text/javascript"> // Right Click disabled on Image only $(document).ready(function() { $("img").on("contextmenu",function(e){ return false; }); }); </script>
You can see the live demo by clicking on the below button or you can also download the code Anytime.
Note: Don’t forget to add jquery library otherwise code will not work.
I hope you will like Disable Mouse Right Click Using Jquery. If You found it useful please subscribe my blog
Categories: Website Design
Leave a Reply