Her

Home Web Programming JavaScript Prevent Right-clicking

Prevent Right-clicking

Author: dannesdesign Author's URL: dannesdesign.com More by this author

Prevent Right-clickingIf you don't want your visitors to rightclick at your page, you can insert this code somewhere between <Body> and </Body>. Type in the message you want your visitors to get in the line "Write your message here"

<script language=JavaScript>
<!--

var message="Write your message here";

///////////////////////////////////
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>