Website Scripts And Cloud Tutorials

Disabling right click and alert message using javascript

Byadmin

Jun 3, 2009

Last updated on March 1st, 2022 at 02:48 pm

Click to rate this tutorial!
[Total: 16 Average: 4.4]

This is an enhanced version of how to disable right click menu from a webpage. This script also has the ability to alert message to the user. If you don’t want to use this script we do have a tutorial on adding a one liner , disable right click using single line of code

You can customize the message displayed to your user by updating this line.

var message="Sorry this function is disabled."

Simple just copy and paste this complete code to an html file and run it.

<title>Disable right click using javascript</title><script type="text/javascript">
var message="Sorry this function is disabled."
function IE4(){
if(event.button==2){
alert(message)
return false}}
function NS4(e){
if(document.layers||document.getElementById&&!document.all){
if(e.which==2||e.which==3){
alert(message)
return false}}}
function disableselect(e){
return false}
function reEnable(){
return true}
document.onselectstart=new Function("return false")
if(window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable}
if(document.layers){
document.captureEvents(Event.MOUSEDOWN)
document.onmousedown=NS4}
else if(document.all&&!document.getElementById){
document.onmousedown=IE4}
document.oncontextmenu=new Function("alert(message);return false")
</script>
<h2>Right Click On The Page</h2>

Some issue was there with the script. It is updated now!!! Working like a charm. Thanks to my visitor BartNKCMO for poiiting out the error.

Enjoy!!

Demo

Click to rate this tutorial!
[Total: 16 Average: 4.4]
11 thoughts on “Disabling right click and alert message using javascript”
  1. Can you give an example as to where to insert this coding ? I am pretty new to this coding stuff and could use all the help anyone can give. This is what I have so far .

  2. In regards to this coding I am a newbie and would appreciate if you could tell me where I insert it into the video js coding this is what I have so far

    _V_.options.flash.swf = “http://elegant-transport.com/swf/video-js.swf”

    1. Hi, You can paste this code anywhere in your website page. Since this is a javascript usually it should go inside the head tags. But that is only a rule :).

    2. Hello, I deeply apologize for the inconvenience caused. There was some error inside the script which created some extra tags when you copy. Thank you very much for bringing this issue into my notice. The script has been updated now.

    1. Yes it is, inside the embed tag give menu=”false”, it should be something like this

      <EMBED src=video.swf type="text/html; charset=iso-8859-1" quality="high" menu="false" WIDTH="100%" HEIGHT="100%">
      

      This should do the trick.

Leave a Reply

Your email address will not be published.