Member Avatar for Member #1110214

I need a Javascript Code to prevent users from right clicking on my website..
alot of people tell me why would you do that? the people will hate your site.
but my site has a whole lot of images and videos i made myself and u know these stupid people who go stealing images, removing your watermark and posting them on their website without giving credits..
yes, theft.
So, Yea i need to block right click.
any codes available?

Dani AI

Generated

As , and pointed out, stopping the context menu is trivial but won’t stop a determined copier. The practical path is two-fold: a lightweight client-side deterrent if you must (knowing it only stops casual users), and stronger server-side controls and watermarking for real protection.

A minimal JavaScript blocker you can drop into a page:

// disables right-click context menu
document.addEventListener('contextmenu', function(e) {
  e.preventDefault();
}, false);

// fallback for older browsers
document.oncontextmenu = function() { return false; };

Caveats: this blocks some accessibility tools and power users can re-enable it or fetch images from the network/devtools. Use it only if you accept the UX tradeoff.

For meaningful protection, implement on-the-fly server-side watermarking (as suggested) and serve lower-resolution previews publicly. Example ImageMagick commands to burn a visible watermark into delivered images:

# overlay a watermark image
convert input.jpg watermark.png -gravity southeast -geometry +10+10 -composite output.jpg

# add semi-transparent text
convert input.jpg -gravity southeast -pointsize 24 -fill "rgba(255,255,255,0.5)" -annotate +10+10 "© YourName" output.jpg

Cache the generated images and keep originals offline when possible.

For video, use tokenized/signed URLs and streaming (HLS/DASH) so links expire; for stronger control consider DRM via a streaming provider. Finally, track misuse with reverse-image search, keep originals and metadata as proof of ownership, and use takedown/DMCA routes when you find copies. These steps won’t make theft impossible, but they make it harder and give you options to enforce your rights.

Recommended Answers

All 3 Replies

right click disabled or not, if someone wants to steal your images or video, they will. watermark your own stuff, sue when you find someone using your work.

This concept is not new, but if read up, you'll find that preventing someone from grabbing your content is not really attainable just by disabling the right click. You see...the fact that the content (text and images) have to be downloaded to the client means that they are available to the end user.

I can see the source code by using the dev tools on my browser. All of hte HTML will be there, including the location of where the images are stored.

Even if you were able to hide all of that markup, I can get a packet capture and see where the stuff is coming from.

I can also just take a screenshot of your web page and edit it in any image editing program.

By disabling the right click, you are only going to stop a very, very small number of people, mainly people that with very few computer skills.

ditto all the above, a watermarking script is easy to implement, and idoes not need to modify the images on the server, only while they are served

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.