H5前端js禁止屏蔽F12 审查元素、屏蔽复制粘贴,查看源代码等

主要给大家介绍了关于利用Javascript如何禁止浏览器右键查看元素,或者通过按F12审查元素,触犯这两个条件会自动并关闭页面的相关资料,通过设置这个可以防止别人扒下自己的网页,需要的朋友可以参考借鉴,下面来一起看看吧。

一、屏蔽F12 审查元素

  1. <script>
  2. document.onkeydown = function () {
  3. if (window.event && window.event.keyCode == 123) {
  4. alert("F12被禁用");
  5. event.keyCode = 0;
  6. event.returnValue = false;
  7. }
  8. if (window.event && window.event.keyCode == 13) {
  9. window.event.keyCode = 505;
  10. }
  11. if (window.event && window.event.keyCode == 8) {
  12. alert(str + "\n请使用Del键进行字符的删除操作!");
  13. window.event.returnValue = false;
  14. }
  15. }
  16. </script>

二、屏蔽右键菜单

  1. <script>
  2. document.oncontextmenu = function (event) {
  3. if (window.event) {
  4. event = window.event;
  5. }
  6. try {
  7. var the = event.srcElement;
  8. if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
  9. return false;
  10. }
  11. return true;
  12. } catch (e) {
  13. return false;
  14. }
  15. }
  16. </script>

三、屏蔽粘贴

  1. <script>
  2. document.onpaste = function (event) {
  3. if (window.event) {
  4. event = window.event;
  5. }
  6. try {
  7. var the = event.srcElement;
  8. if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
  9. return false;
  10. }
  11. return true;
  12. } catch (e) {
  13. return false;
  14. }
  15. }
  16. </script>

四、屏蔽复制

  1. <script>
  2. document.oncopy = function (event) {
  3. if (window.event) {
  4. event = window.event;
  5. }
  6. try {
  7. var the = event.srcElement;
  8. if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
  9. return false;
  10. }
  11. return true;
  12. } catch (e) {
  13. return false;
  14. }
  15. }
  16. </script>

五、屏蔽剪切

  1. <script>
  2. document.oncut = function (event) {
  3. if (window.event) {
  4. event = window.event;
  5. }
  6. try {
  7. var the = event.srcElement;
  8. if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
  9. return false;
  10. }
  11. return true;
  12. } catch (e) {
  13. return false;
  14. }
  15. }
  16. </script>

六、屏蔽选中

  1. <script>
  2. document.onselectstart = function (event) {
  3. if (window.event) {
  4. event = window.event;
  5. }
  6. try {
  7. var the = event.srcElement;
  8. if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
  9. return false;
  10. }
  11. return true;
  12. } catch (e) {
  13. return false;
  14. }
  15. }
  16. </script>
文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/1215
1 条评论
2.1k

发表评论

!