add

About Me

My photo
Oracle Apps - Techno Functional consultant

Friday, September 9

Java Script to Disable Right click and left click in website/blog ...


We can achieve this even for blogs by adding new gadget(HTML/JAVA script) abd paste the below script and save.

You can show the messgae window to users when right clicked by adding yoour own message in message variable.
If you are not clear replace "Sample Messgae" with your own message from the below script .

If you dont want to show the message box, then follow the Note mentioned in script.


<script language="JavaScript">
<!--
//Disable right click
var message=" Sample Message";
function Rtclick(){
if (event.button==2){
alert(message);
return false;
}}
function Rtclick1(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=Rtclick1;
}
else if (document.all&&!document.getElementById){
document.onmousedown=Rtclick;
}
document.oncontextmenu=new Function("alert(message);return false")
// Note : If you dont want show the allert message to users comment the above line by adding //
// and remove the comments from below line (i.e remove // from the begining)
//document.oncontextmenu=new Function ("return false")
//Disable select-text script (IE4+, NS6+)-
function disableselect(e){
return false
}
function reEnable(){
return true
}
//if IE4+
document.onselectstart=new Function ("return false")
//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
// -->
</script>




----------------------------------------------------------
script that I have tested and working perfectly
----------------------------------------------------------



<script language="JavaScript">
<!--


//Disable right click


var message="Try again..";




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


function Rtclick1(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=Rtclick1;
}
else if (document.all&&!document.getElementById){
document.onmousedown=Rtclick;
}


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


// If you dont want show the allert message to users //comment the above line by adding //
// and remove the comments from below line (i.e remove // from the begining)


document.oncontextmenu=new Function ("return false")




//Disable select-text script (IE4+, NS6+)- By Andy Scott
//Exclusive permission granted to Dynamic Drive to feature script
//Visit http://www.dynamicdrive.com for this script

function disableselect(e){
return false
}

function reEnable(){
return true
}

//if IE4+
document.onselectstart=new Function ("return false")

//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}




// -->
</script>

No comments: