Sunday, July 20, 2008

Disable the Right click option in the Webpage

1. write the below function in the script tag:
function click(e)
{
if (document.all)
{
if (event.button==2event.button==3)
{
oncontextmenu='return false';
}
}
if (document.layers)
{
if (e.which == 3)
{
oncontextmenu='return false';
}
}
}
if (document.layers)
{
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
function handleKeyDown()
{
if (window.event.keyCode == 116)
{
event.keyCode=0;
event.returnValue=false;
}
}
document.onkeydown = handleKeyDown;

2. In Body Tag:

call the funtion in the events as follows:
oncontextmenu="return false"
ondragstart="return false"
onselectstart="return false"


3. write this inside the script tag:

function click(e) {
if (document.all) {
if (event.button==2event.button==3) {
oncontextmenu='return false';

}
}

if (document.layers) {
if (e.which == 3) {
oncontextmenu='return false';
}
}
}

if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;

function handleKeyDown() {
if (window.event.keyCode == 116) {
event.keyCode=0;
event.returnValue=false;
}
}
document.onkeydown = handleKeyDown;

No comments: