网站既包含PC端页面,又包括手机端页面时,打开手机端自动跳转手机页面,js代码如下

<script type="text/javascript">
var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate",
       "bada", "nokia", "lg", "ucweb", "skyfire");
var browser = navigator.userAgent.toLowerCase();
var isMobile = false;
for (var i=0; i<mobileAgent.length; i++) {
if (browser.indexOf(mobileAgent[i])!=-1) {
isMobile = true;
location.href = '#';//要跳转的网址
break;
}
}
</script>

第二种

<script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script>
<script type="text/javascript">uaredirect("你的手机版网址");</script>

第三种

<script language="javascript">
function is_mobile() {
var regex_match = /(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm|jigs browser|hiptop|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220)/i;
var u = navigator.userAgent;
if (null == u) {
return true;
}
var result = regex_match.exec(u);
if (null == result) {
return false
} else {
return true
}
} function QueryString(item) {
var sValue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)", "i"))
return sValue ? sValue[1] : sValue
}
if (QueryString("ID") != "t" && is_mobile()) {
document.location.href = '#';//要跳转的网址
}
</script>

最新文章

  1. LINUX常见问题
  2. Rails--抛出异常
  3. imadjust从用法到原理—Matlab灰度变换函数之一
  4. 【hiho一下第77周】递归-减而治之 (MS面试题:Koch Snowflake)
  5. Ruby准备工作
  6. 推送通知/传感器/UIDynamic仿真(推送通知已适配iOS10)
  7. VB.NET入门基础
  8. 2.x ESL第二章习题 2.8
  9. python unitest基本
  10. Security+高分考过经验分享812分
  11. lambada表达式
  12. SharePoint Framework 在web部件中使用已存在的JavaScript库 - JavaScript库的格式
  13. Flink集群部署
  14. office2007每次打开都要配置文件,怎么取消配置(可行)
  15. 美团2018年CodeM大赛-初赛B轮 C题低位值
  16. Android 解决在初次打开Activity加载布局文件时,ScrollView滚动条不在顶部的问题
  17. android webview内存泄露解决方法
  18. eval解析字符串为JSON对象
  19. Python MySQLdb insert(插入) 封装
  20. grub覆盖mbr引导系统

热门文章

  1. 【c#】csharp_learn
  2. 分区函数Partition by使用
  3. Angular单页应用程式 (SPA)+Azure AD重新导向登入
  4. Linux系统Shell脚本第三章:for、while循环及脚本实操
  5. Win10系统桌面exe文件图标消失不见了的解决方法
  6. win10系统每次重启桌面图标排列都会改动怎么办
  7. 云函数调用云函数 openid不存在
  8. FCOS网络(free anchor)
  9. uniapp引入腾讯云直播助手插件
  10. 3月1日至3月2日——数据结构与算法分析阅读笔记,线性表,AI。