JS代码屏蔽鼠标右键和F5刷新实例
来源:自学PHP网
时间:2014-09-19 14:47 作者:
阅读:次
[导读] 本文章给大家介绍一个JS代码屏蔽鼠标右键和F5刷新实例,希望此方法对各位同学会有所帮助哦。...
以下为本篇文章全部内容:
代码如下 |
复制代码 |
<script type="text/javascript">
document.oncontextmenu = function() {event.returnValue = false;}
//屏蔽右键
function document.onkeydown()//屏蔽刷新
{
if ( event.keyCode==116)
{
event.keyCode = 0;
event.cancelBubble = true;
return false;
}
}
</script>
|
例
代码如下 |
复制代码 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="JavaScript">
document.oncontextmenu = ppMousedownOfRight;
document.onkeydown = ppPressF5;
if (window.addEventListener) {
FixPrototypeForGecko(); //是Firefox
}
function FixPrototypeForGecko() {
window.constructor.prototype.__defineGetter__("event", window_prototype_get_event);
}
function window_prototype_get_event() {
return SearchEvent();
}
function SearchEvent() {
if (document.all)
return window.event;
func = SearchEvent.caller;
while (func != null) {
var arg0 = func.arguments[0];
if (arg0 instanceof Event) {
return arg0;
}
func = func.caller;
}
return null;
}
//禁止用F5键
function ppPressF5(){
if(event.keyCode==82 && event.ctrlKey)
{
event.keyCode=0;
event.returnValue=false;
return false;
}
if(event.keyCode==62 && event.ctrlKey)
{
event.keyCode=0;
event.returnValue=false;
return false;
}
if(event.keyCode==68 && event.ctrlKey)
{
event.keyCode=0;
event.returnValue=false;
return false;
}
if(event.keyCode==77 && event.ctrlKey)
{
event.keyCode=0;
event.returnValue=false;
return false;
}
if(event.keyCode==82 && event.ctrlKey)
{
event.keyCode=0;
event.returnValue=false;
return false;
}
if(event.keyCode==85 && event.ctrlKey)
{
event.keyCode=0;
event.returnValue=false;
return false;
}
if(event.keyCode==116)
{
event.keyCode=0;
event.returnValue=false;
return false;
}
}
//禁止右键弹出菜单
function ppMousedownOfRight(){
event.cancelBubble = true
event.returnValue = false;
return false;
}
</script>
</script>
</head>
<body>
aaaaaa1a2aaaaaaaaaaa
</body>
</html>
|
|