子比主题 – 禁用右键、禁用F12、复制提醒

美化说明

子比主题添加一个禁用右键、禁用F12、复制成功的提醒弹窗,这些都是简易代码,只能防止小白,真想扒站是防不住的,所以本篇文章就是分享一个防止小白的弹窗

效果展示

图片[1]-子比主题 – 禁用右键、禁用F12、复制提醒-太阳博客

代码部署

首先将下面的代码添加到 /wp-content/themes/zibll/header.php 或者 子比主题设置 – 全局功能 – 自定义代码 – 自定义底部HTML代码 两种方式都可以

<!-- 引入VUE -->
<script src="https://unpkg.com/vue@2.6.14/dist/vue.min.js"></script>
<!-- 引入样式 -->
<script src="https://unpkg.com/element-ui@2.15.6/lib/index.js"></script>
<!-- 引入组件库 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui@2.15.6/packages/theme-chalk/lib/index.css">

第二步

将下面的 JS代码1 添加到 /wp-content/themes/zibll/header.php ,也可以选择将 JS代码2 放在 自定义底部HTML代码 中,放后台有些不生效,所以放在php比较稳

JS 代码

/* 添加到 header.php 文件中 */
<script>
document.onkeydown=function(event) {
  if (event.keyCode==123) {
    // 禁止F12
    event.preventDefault();

    new Vue( {
      data: function() {
        this.$notify( {
          title: "呃!别瞎按",
            message: "你按这个想干嘛!F12已经禁止咯",
            position: 'bottom-right',
            offset: 50,
            showClose: false,
            type: "error"
        });
        return {
          visible: false
        }
      }
    }) 
     return false;
  }
};
</script>

<script>
document.addEventListener("copy", function(e) {
  new Vue( {
    data: function() {
      if((window.getSelection ? window.getSelection(): document.selection.createRange().text) !='') {
        this.$notify( {
          title: "叮!复制成功",
            message: "若要转载请务必保留原文链接!谢谢~",
            position: 'bottom-right',
            offset: 50,
            showClose: true,
            type: "success"
        });
      }

      else {
        this.$notify( {
          title: "咦?复制失败",
            message: "啊噢...你没还没选择内容呢!",
            position: 'bottom-right',
            offset: 50,
            showClose: true,
            type: "success"
        });
      }

      return {
        visible: false
      }
    }
  })
}) 
</script>
/* 添加到自定义底部 HTML 代码 */
/* 禁止F12 */
document.onkeydown=document.onkeyup=document.onkeypress=function () {
  if (window.event.keyCode==123) {
    window.event.returnValue=false;
    return (false);
  }
}

/* 复制提醒 */
document.addEventListener("copy", function(e) {
  new Vue( {
    data:function() {
      this.$notify( {
        title: "嘿!复制成功",
          message:"若要转载请务必保留原文链接!谢谢~",
          position: 'bottom-right',
          offset: 50, showClose: false, type:"success"
      });
      return {
        visible: false
      }
    }
  })
})

/* 禁用右键提醒 */
document.oncontextmenu=function () {
  new Vue( {
    data:function() {
      this.$notify( {
        title: "嘿!没有右键菜单",
          message:"复制请用键盘快捷键",
          position: 'bottom-right',
          offset: 50, showClose: false, type:"warning"
      });
      return {
        visible: false
      }
    }
  }) 
   return false;
}
温馨提示:本文最后更新于2026-05-21 11:23:31,若文章、图片或者链接失效,请在评论留言反馈!
THE END
喜欢就支持一下吧!
点赞14赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容