Home > Tips & Tricks > How to Disable right click on Website Using HTML Attribute?

How to Disable right click on Website Using HTML Attribute?

Hey! do you know HTML has its own way of using a special attribute to disable the right click on the website or any specific section?

No?

Don’t worry!!!

I will tell you in this trick how you can disable the right click on the whole web page or any section that you only want on that.

It is very simple to disable the right click using the HTML attribute. You just have to pass the oncontextmenu attribute to the body tag with returning value false. See the following code.

To disable right click on full website

Using the above HTML attribute with a body tag will disable the right click on the full website.

To disable right click on specific section

If you want to disable right-click only on specific sections like header, footer, navbar, sidebar, etc. Then you can also do that with this attribute. You just have to add that attribute for that specific section.

The above example code will disable the right-click on the aside tag.

Being Tricky 😉

Photo of author

About Aman Mehra

Hey there! I'm Aman Mehra, a full-stack developer with over six years of hands-on experience in the industry. I've dedicated myself to mastering the ins and outs of PHP, WordPress, ReactJS, NodeJS, and AWS, so you can trust me to handle your web development needs with expertise and finesse. In 2021, I decided to share my knowledge and insights with the world by starting this blog. It's been an incredible journey so far, and I've had the opportunity to learn and grow alongside my readers. Whether you're a seasoned developer or just dipping your toes into the world of web development, I'm here to provide valuable content and solutions to help you succeed. So, stick around, explore the blog, and feel free to reach out if you have any questions or suggestions. Together, let's navigate the exciting world of web development!

Leave a Comment