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

移动端访问网站持续自动刷新 相关JS跳转代码如何修复?

问题根源

无限刷新是重定向死循环导致:你当前的UA判断跳转代码同时放在了桌面端页面(如index.html)和mobile.html两个文件中。移动端设备访问任意页面时都会触发跳转规则,反复重定向到mobile.html,形成无限循环。

修复方案

方案1:修改跳转逻辑(推荐)

  • 先清理冲突的viewport配置,删除固定宽度的冗余声明,仅保留响应式适配的viewport:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 移除下方冲突的viewport配置 -->
<!-- <meta name="viewport" content="width=1500px, maximum-scale=1.0" /> -->
  • 给跳转逻辑增加页面路径判断,只有当前页面不是mobile.html时才执行跳转:
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|OperaMini/i.test(navigator.userAgent) 
&& !window.location.pathname.includes('mobile.html')) {
  document.location = "mobile.html";
}
  • 可选优化:如果需要支持用户手动切换到桌面版,可以增加本地存储标记判断,避免用户选择桌面版后又被强制跳回移动端:
const isMobileDevice = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|OperaMini/i.test(navigator.userAgent);
const isNotMobilePage = !window.location.pathname.includes('mobile.html');
const noManualSkip = !localStorage.getItem('skip_mobile_redirect');

if (isMobileDevice && isNotMobilePage && noManualSkip) {
  document.location = "mobile.html";
}

// 桌面版页面添加「切换到桌面版」按钮,点击时执行下方代码即可保存用户选择
// localStorage.setItem('skip_mobile_redirect', '1');

方案2:拆分代码放置位置

直接将这段UA跳转代码从mobile.html页面中完全删除,仅保留在桌面端页面中,也可以直接解决死循环问题。

内容的提问来源于stack exchange,提问作者Krishay Rastogi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.08 19:18:05