1. 程式人生 > >網頁右鍵、複製、另存為、快取等功能的禁用以及F12禁用

網頁右鍵、複製、另存為、快取等功能的禁用以及F12禁用

1、右鍵禁用

方法1:

document.oncontextmenu = function () {
    return false;
}
方法2
document.onmousedown = function () {
    if (event.button == 2) {
        return false;
    }
}
2、複製
<script> 
function noCopy() 
{ 
	event.returnValue = false; 
} 
</script> 
<body oncopy = "noCopy()"> 
3、另存為

在<body>內容主體中加入<noscript><iframe src='*.html'></iframe></noscript>

4、快取禁用

<head>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Cache-Control" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
</head>

5、F12禁用


方法1:

document.onkeydown = function (e) {
    var currentKey = 0, k = e || window.event;
    currentKey = k.keyCode || k.which || k.charCode;
    if (currentKey == 123) {
        window.event.cancelBubble = true;
        window.event.returnValue = false;
    }
}

方法2:

document.onkeydown = function () {
    if (window.event && window.event.keyCode == 123) {
        window.event.returnValue = false;
    }
}