Thursday, June 7, 2007

Disable the context menu

For security reasons,sometimes we want that the user should not be able to see the source code of the web page that can be done choosing view source option from the context menu. So best way is to hide the context menu. For that write a javascript function and pass it to the oncontextmenu attribute of the body tag. Example-

body oncontextmenu="return HideContext();"


javascript function -
function HideContext()
{
alter('Context Menu not availabe.');
return false;
}

Disable the selection of the web page's contents.

But sometimes we want that the user should not be able to select the content of the web page. For that return false to the onselectstart attribute of the body tag. Example-

body onselectstart="return false"

No comments: