Last updated on March 1st, 2022 at 02:48 pm
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!!
How to make this work for FF?
Hello,
This will work fine both in IE and FF…please test it once..thanks….OR get back with your concerns…..
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 .
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”
tried topaste code but all it did was post a link ugh
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 :).
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.
Is it possible to disable right click on the full screen video?
Yes it is, inside the embed tag give menu=”false”, it should be something like this
This should do the trick.
Very useful..!!
Very good script, boring is that to spoil all just disable “enable javascript” browser