可以使用JavaScript来实现判断当前浏览器类型并进行跳转。具体实现如下:

  1. 判断是否为QQ或微信浏览器:
var isQQ = navigator.userAgent.indexOf('QQ/') !== -1;
var isWechat = navigator.userAgent.indexOf('MicroMessenger') !== -1;
  1. 判断是否为手机浏览器:
var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
  1. 根据判断结果进行跳转:
if (isQQ || isWechat) {
  // 在QQ或微信浏览器中,禁止跳转
  alert('请使用浏览器打开');
} else if (isMobile) {
  // 在手机浏览器中,跳转到移动端页面
  window.location.href = 'https://m.example.com';
} else {
  // 在PC浏览器中,跳转到PC端页面
  window.location.href = 'https://www.example.com';
}

完整代码如下:

var isQQ = navigator.userAgent.indexOf('QQ/') !== -1;
var isWechat = navigator.userAgent.indexOf('MicroMessenger') !== -1;
var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);

if (isQQ || isWechat) {
  alert('请使用浏览器打开');
} else if (isMobile) {
  window.location.href = 'https://m.example.com';
} else {
  window.location.href = 'https://www.example.com';
}

原文地址: https://www.cveoy.top/t/topic/jqkc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录