1.
屏蔽右键,
只要设置document.oncontextmenu = function(){return false;}
2.
右键为我所用
<
html
>
< head >
< title > 页面右键的响应 </ title >
< script language = " javascript " >
function hidemenu()
{
document.oncontextmenu =
function(){ return false ;}
}
function showmenu()
{
document.oncontextmenu =
function(){ return true ;}
}
function showcustommenu()
{
document.oncontextmenu =
function(){
alert( ' 自定义响应 ' );
return false ;
// 这里的return false是必要的
}
}
</ script >
</ head >
< body onload = " hidemenu(); " >
默认响应右键: < input type = " text " id = " text1 " onfocus = " showmenu(); " onblur = " hidemenu(); " >
< br >
自定义响应右键: < input type = " text " id = " text1 " onfocus = " showcustommenu(); " onblur = " hidemenu(); " >
< br >
不响应右键: < input type = " text " id = " text2 " >
</ body >
</ html >
< head >
< title > 页面右键的响应 </ title >
< script language = " javascript " >
function hidemenu()
{
document.oncontextmenu =
function(){ return false ;}
}
function showmenu()
{
document.oncontextmenu =
function(){ return true ;}
}
function showcustommenu()
{
document.oncontextmenu =
function(){
alert( ' 自定义响应 ' );
return false ;
// 这里的return false是必要的
}
}
</ script >
</ head >
< body onload = " hidemenu(); " >
默认响应右键: < input type = " text " id = " text1 " onfocus = " showmenu(); " onblur = " hidemenu(); " >
< br >
自定义响应右键: < input type = " text " id = " text1 " onfocus = " showcustommenu(); " onblur = " hidemenu(); " >
< br >
不响应右键: < input type = " text " id = " text2 " >
</ body >
</ html >
红叶的专栏---“用javascript实现既能禁止页面鼠标右键查看 同时又能查看页面文本框右键菜单 ”