Skip to main content

Command Palette

Search for a command to run...

How to disable right-click on your website?

Published
•1 min read
How to disable right-click on your website?
D

I am 17 years old and a young passionate and self-taught frontend web developer and have an intention to become a successful developer. I usually write about JavaScript and Web Development and share some tips in the articles.

Disabling right-click on websites provides basic security so that people don't save images and copy links and text.

Today, in this article I will show you how you can also disable right-click on your website.

Let's disable the right-click

To disable right-click on the website, we have to deal with JavaScript. It's pretty simple to disable right-click. Let me show you...

document.addEventListener('contextmenu', event => event.preventDefault());

Tada! Right-click has been disabled on your website 🎊

Conclusion

I hope this blog post has helped you understand how to disable right-clicking on websites.

Let’s connect

If you found my content helpful and would like to thank me, feel free to Buy me a coffee :)

Have a great day!

T
Tiia4y ago

It's important to not tho, that this is a big accessibility flaw and you should avoid using this practice unless you have no other option. But usually you have.

4
D

Totally agree with you, Tiia! Even I have never disabled right-click in any project. I have shared this article just to share my knowledge with other folks 🙂

Thanks for reading! Have a good day!

More from this blog

D

Dhairya Shah

119 posts