Script To Disable The Right-Click

Post new topic   Reply to topic

View previous topic View next topic Go down

Script To Disable The Right-Click

Post by Master Marc on July 15th 2009, 3:06 pm

Script To Disable The Right-Click On An HTML Page


This tutorial will help you disable the right click of the mouse on your html pages.

There are many codes that can help you with this,but am going to give you one script code that will make this possible.

This script code will allow you to disable the right mouse click by adding it between your body tags ~ <body></body>.And will also display a pop-up message.

Code:

<script language=JavaScript>
<!--

//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com

var message="Click Disabled";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")

// -->
</script>


Example of this code on my forum ~ Click Here

You can modify the code {the bold part below} if you'd like to change the message that will appear in the pop-up box.

var message="Click Disabled";


Also,there is another code you can use if you don't want the pop-up box.

Code:

<BODY oncontextmenu="return false"
</body>


Add this code in your body tags {<body></body>} and it will silently disable right clicks from your mouse.

Example of this code on my forum ~ Click Here



Script To Disable Right Click On Your Forum


Go to your administration panel=>General Tab=>Forum=>Configuration=>General=>Site description=>Add this code

Code:
<script language=Javascript1.2> function ejs_nodroit() { alert('Text Here'); return(false); } document.oncontextmenu = ejs_nodroit; </script>


You can modify the message you receive when someone right clicks by editing the code's text that says : Text Here

If you would like no pop-up version,you can add this code instead.

Code:
<BODY oncontextmenu="return false"</body>



Written by Master Marc
Updated by MrMario as requested by Master Marc

Master Marc
Forumotion Member

Male
Posts: 2889
Age: 15
Language: English / HTML / XHTML /CSS / JavaScript / [ Trying to master php ]
Location: Forumotion's english and french support forums, ;)
Country:
Join date: 2008-12-18

http://www.iwebbuddy.com/

Back to top Go down

View previous topic View next topic Back to top


Permissions of this forum:
You cannot reply to topics in this forum