Last active
August 8, 2020 15:53
-
-
Save Lincest/b9592d33eaf5e74c090a373c5a7f01ed to your computer and use it in GitHub Desktop.
保护源码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
document.onkeydown = function(){ | |
if(window.event && window.event.keyCode == 123) { | |
alert("F12 is blocked"); | |
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; | |
} | |
if ((window.event && window.event.keyCode == 83) ) { //ctrl+s | |
alert("ctrl+s被禁用"); | |
return 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.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; | |
} | |
} | |
// 或者替换为以下语句说明版权 | |
// document.body.addEventListener('copy', function(e) { | |
// if (window.getSelection().toString() && window.getSelection().toString().length > 0) { | |
// setClipboardText(e); | |
// alert('复制成功!'); | |
// } | |
// }); | |
// function setClipboardText(event) { | |
// var clipboardData = event.clipboardData || window.clipboardData; | |
// if (clipboardData) { | |
// event.preventDefault(); | |
// var htmlData = '' | |
// + '著作权归作者所有。<br>' | |
// + '商业转载请联系作者获得授权,非商业转载请注明出处。<br>' | |
// + '作者:<?php $this->author() ?><br>' | |
// + '链接:' + window.location.href + '<br>' | |
// + '来源:<?php $this->options->siteUrl(); ?><br><br>' | |
// + window.getSelection().toString(); | |
// var textData = '' | |
// + '著作权归作者所有。\n' | |
// + '商业转载请联系作者获得授权,非商业转载请注明出处。\n' | |
// + '作者:<?php $this->author() ?>\n' | |
// + '链接:' + window.location.href + '\n' | |
// + '来源:<?php $this->options->siteUrl(); ?>\n\n' | |
// + window.getSelection().toString(); | |
// clipboardData.setData('text/html', htmlData); | |
// clipboardData.setData('text/plain', textData); | |
// } | |
// } | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment