设为首页收藏本站心情墙手机版 今天是: 2024-04-26    "世界知识产权日"  突出知识产权在所有国家的经济、文化和社会发展中的作用和贡献
天气与日历 切换到宽版

 找回密码
 立即注册
搜索
查看: 385|回复: 0

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

[复制链接]
  • 打卡等级:LV6

452

主题

30

回帖

24万

积分

管理员

积分
247191

突出贡献荣誉管理论坛元老本科学士学位拥有劳力士宇宙计型迪通拿系列m116515ln-0059拥有欧米茄星座系列131.23.41.21.03.001拥有梅赛德斯-奔驰EQS 580 4MATIC拥有宝马M8四门轿跑车 雷霆版

QQ

皮卡丘 Lv:40
发表于 2022-12-31 10:54:13 | 显示全部楼层 |阅读模式 IP:北京


本页内容包含:屏蔽F12、屏蔽Ctrl+Shift+I、屏蔽Shift+F10、屏蔽Ctrl+U、屏蔽右键单击、屏蔽F12 审查元素、屏蔽右键菜单、屏蔽粘贴、屏蔽复制、屏蔽剪切、屏蔽选中。
直接复制以下代码粘贴到页面中即可:
  1. <script language="javascript">
  2. window.onload = function() {
  3. document.onkeydown = function() {
  4. var e = window.event || arguments[0];
  5. //屏蔽F12
  6. if(e.keyCode == 123) {
  7. return false;
  8. //屏蔽Ctrl+Shift+I
  9. } else if((e.ctrlKey) && (e.shiftKey) && (e.keyCode == 73)) {
  10. return false;
  11. //屏蔽Shift+F10
  12. } else if((e.shiftKey) && (e.keyCode == 121)){
  13. return false;
  14. //屏蔽Ctrl+U
  15. } else if((e.ctrlKey) && (e.keyCode == 85)){
  16. return false;
  17. }
  18. };
  19. //屏蔽右键单击
  20. document.oncontextmenu = function() {
  21. alert("右键被禁止,复制内容请按CTRL+C!");
  22. return false;
  23. }
  24. }
  25. //屏蔽F12 审查元素
  26. document.onkeydown = function(){
  27. if(window.event && window.event.keyCode == 123) {
  28. alert("F12被禁用");
  29. event.keyCode=0;
  30. event.returnValue=false;
  31. }
  32. if(window.event && window.event.keyCode == 13) {
  33. window.event.keyCode = 505;
  34. }
  35. if(window.event && window.event.keyCode == 8) {
  36. alert(str+"\n请使用Del键进行字符的删除操作!");
  37. window.event.returnValue=false;
  38. }
  39. }
  40. //屏蔽右键菜单
  41. document.oncontextmenu = function (event){
  42. if(window.event){
  43. event = window.event;
  44. }try{
  45. var the = event.srcElement;
  46. if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
  47. return false;
  48. }
  49. return true;
  50. }catch (e){
  51. return false;
  52. }
  53. }
  54. //屏蔽粘贴
  55. document.onpaste = function (event){
  56. if(window.event){
  57. event = window.event;
  58. }try{
  59. var the = event.srcElement;
  60. if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
  61. return false;
  62. }
  63. return true;
  64. }catch (e){
  65. return false;
  66. }
  67. }
  68. //屏蔽复制
  69. document.oncopy = function (event){
  70. if(window.event){
  71. event = window.event;
  72. }try{
  73. var the = event.srcElement;
  74. if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
  75. return false;
  76. }
  77. return true;
  78. }catch (e){
  79. return false;
  80. }
  81. }
  82. //屏蔽剪切
  83. document.oncut = function (event){
  84. if(window.event){
  85. event = window.event;
  86. }try{
  87. var the = event.srcElement;
  88. if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
  89. return false;
  90. }
  91. return true;
  92. }catch (e){
  93. return false;
  94. }
  95. }
  96. //屏蔽选中
  97. document.onselectstart = function (event){
  98. if(window.event){
  99. event = window.event;
  100. }try{
  101. var the = event.srcElement;
  102. if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
  103. return false;
  104. }
  105. return true;
  106. } catch (e) {
  107. return false;
  108. }
  109. }
  110. </script>
复制代码


急躁,是因为经历不够,轻浮,是因为磨练不够,烦乱,是因为思路不清,压力,是因为格局不够,恐惧,是因为假想太多,在这个薄凉的世界,自己不强大,一切都是浮云 ...
懒得打字嘛,点击右侧快捷回复 【乱回复纯数字纯字母将禁言】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|社区规范|绵羊优创 ( 京ICP备19037745号-2 )|网站地图

公安备案京公网安备11011502037529号

GMT+8, 2024-4-26 05:14 , Processed in 1.265342 second(s), 19 queries , MemCache On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表