sheep 发表于 2022-12-31 10:54:13

js禁止查看网页源码代码(含禁止复制粘贴)



本页内容包含:屏蔽F12、屏蔽Ctrl+Shift+I、屏蔽Shift+F10、屏蔽Ctrl+U、屏蔽右键单击、屏蔽F12 审查元素、屏蔽右键菜单、屏蔽粘贴、屏蔽复制、屏蔽剪切、屏蔽选中。
直接复制以下代码粘贴到页面中即可:
<script language="javascript">
window.onload = function() {
document.onkeydown = function() {
var e = window.event || arguments;
//屏蔽F12
if(e.keyCode == 123) {
return false;
//屏蔽Ctrl+Shift+I
} else if((e.ctrlKey) && (e.shiftKey) && (e.keyCode == 73)) {
return false;
//屏蔽Shift+F10
} else if((e.shiftKey) && (e.keyCode == 121)){
return false;
//屏蔽Ctrl+U
} else if((e.ctrlKey) && (e.keyCode == 85)){
return false;
}
};
//屏蔽右键单击
document.oncontextmenu = function() {
alert("右键被禁止,复制内容请按CTRL+C!");
return false;
}
}
//屏蔽F12 审查元素
document.onkeydown = function(){
if(window.event && window.event.keyCode == 123) {
alert("F12被禁用");
event.keyCode=0;
event.returnValue=false;
}
if(window.event && window.event.keyCode == 13) {
window.event.keyCode = 505;
}
if(window.event && window.event.keyCode == 8) {
alert(str+"\n请使用Del键进行字符的删除操作!");
window.event.returnValue=false;
}
}
//屏蔽右键菜单
document.oncontextmenu = function (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;
}
}
//屏蔽粘贴
document.onpaste = function (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;
}
}
//屏蔽复制
document.oncopy = function (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;
}
}
//屏蔽剪切
document.oncut = function (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;
}
}
//屏蔽选中
document.onselectstart = function (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>

页: [1]
查看完整版本: js禁止查看网页源码代码(含禁止复制粘贴)