Friday, July 3, 2009

Disable right click on web page

We may want to protect our page code from users right clicking over a page and "View Source" and saving it.

Some times there might be a requirement to disable the pop up menu on click of right button.

The following Java script code will display a popup alter saying right click is disabled and prevent the users from viewing source.



< language="javascript">

document.onmousedown=disableRightClick;

Function disableRightClick(e)
{
if(event.button==2)
{
alert("Right Click Disabled");
return false;
}
}
< /script >



document.onmousedown - means the net surfer press the mouse button (Left, right or middle button).

event.button == 2 - means Right click
where as event.button == 1 means Left Click


It will display a popup message "Right Click Disabled" when the surfers right click on the page.

Use this code to stop surfers from easily saving your web page, viewing its source, or lifting images off your site

For more details
http://www.codeproject.com/KB/aspnet/Disabling_the_right_click.aspx

No comments:

Post a Comment