You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用JavaScript/jQuery实现移除版权文本时自动跳转网页

实现不可移除/隐藏的版权文本跳转功能

以下是针对需求的具体实现方案,结合原生JavaScript完成检测与跳转逻辑(兼容jQuery环境):

完整代码示例

<footer>
  <span id='copyright'> Copyright 2023 - Theme Title </span> | All Rights Reserved. 
</footer>

<script>
// 配置项:替换为你的目标跳转URL
const JUMP_URL = 'https://your-target-url.com';
// 检查间隔(毫秒),可按需调整
const CHECK_INTERVAL = 500;

// 版权元素原始文本(可选:用于检测文本是否被篡改)
const ORIGINAL_TEXT = ' Copyright 2023 - Theme Title ';

let checkTimer = setInterval(() => {
  const copyrightEl = document.getElementById('copyright');
  
  // 情况1:版权元素被直接移除
  if (!copyrightEl) {
    redirectToTarget();
    return;
  }

  // 获取元素实际生效的CSS样式
  const computedStyle = window.getComputedStyle(copyrightEl);
  
  // 情况2:元素被通过CSS手段隐藏
  const isHidden = computedStyle.display === 'none' || 
                   computedStyle.visibility === 'hidden' || 
                   parseFloat(computedStyle.opacity) === 0 ||
                   copyrightEl.offsetParent === null;
  
  // 情况3:版权文本被篡改(不需要可删除此判断)
  const textTampered = copyrightEl.textContent.trim() !== ORIGINAL_TEXT.trim();

  if (isHidden || textTampered) {
    redirectToTarget();
  }
}, CHECK_INTERVAL);

// 跳转执行函数
function redirectToTarget() {
  clearInterval(checkTimer);
  window.location.href = JUMP_URL;
}
</script>

关键逻辑说明

  • 定时检测:通过setInterval每隔500毫秒检查一次版权状态,平衡检测灵敏度与性能消耗。
  • 元素存在性校验:如果getElementById('copyright')返回null,判定元素被移除。
  • 多维度可见性检测:覆盖常见的隐藏手段:
    • display:none:完全隐藏且不占据页面空间
    • visibility:hidden:隐藏元素但保留布局空间
    • opacity:0:元素透明不可见
    • offsetParent === null:检测元素是否被父级元素间接隐藏
  • 文本篡改校验(可选):对比元素文本与原始内容,防止用户修改版权信息
  • 强制跳转:触发违规条件后立即清除定时器并跳转目标URL,避免重复触发

补充提示

  • 该功能依赖JavaScript,若用户禁用JS则无法生效,这是前端方案的固有局限性。
  • 可将脚本压缩混淆,提升破解门槛(但无法完全阻止技术水平较高的用户)。

内容的提问来源于stack exchange,提问作者Asma Binta Younus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 07:40:23