网页禁止复制粘贴/禁止右键代码/禁止查看源码js代码
<script type="text/javascript">
// 禁止保存,拖拽图片
for(i in document.images) {
document.images[i].ondragstart = function() {
return false;
};
}
//当键盘按下时
document.onkeydown = function() {
//禁止F12
if(window.event && window.event.keyCode == 123) {
alert("F12调试功能已被禁用请勿使用!");
window.event.keyCode = 0;
window.event.returnValue = false;
}
//禁止Ctrl+U查看源代码
if(event.ctrlKey && window.event.keyCode == 85) {
window.event.returnValue = false;
}
//禁止Ctrl+S网页另存为
if(event.ctrlKey && window.event.keyCode == 83) {
window.event.returnValue = false;
}
if(window.event && window.event.keyCode == 8) {
alert(str + "\n请使用Del键进行字符的删除操作!");
window.event.returnValue = false;
}
}
//屏蔽右键菜单
document.oncontextmenu = disable;
//屏蔽复制
document.oncopy = disable;
//屏蔽粘贴
document.onpaste = disable;
//屏蔽剪切
document.oncut = disable;
//屏蔽选中(选择文字)
document.onselectstart = disable;
function disable(event) {
if(window.event) {
event = window.event;
}
try {
var the = event.srcElement;
if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
return false;
}
return true;
} catch(e) {
return false;
}
}
</script>