快讯资讯
手机优化
系统数码
网络通信人工智能
网站游戏
测评专题
智车

  js判断手机访问或者PC的    

js判断手机访问或者PC的几个例子(常用于手机跳转

时间:2026-09-23 16:56 来源:网络 人气:
123456789101112131415161718192021<script>function browserRedirect() { var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os"; var bIsMidp = sUserAgent.match(/midp/i) == "midp"; var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb"; var bIsAndroid = sUserAgent.match(/android/i) == "android"; var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"; var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile"; if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){ window.location.href='https://www.jb51.net'; }else{ //window.location.href='http://m.jb51.net'; }}$(function(){ browserRedirect();});</script>

例子2


123456789101112131415161718192021<script type="text/javascript">(function(){ var reWriteUrl = function(url){ if(url){ var Splits = url.split("/"),siteName=window.location.pathname; if(typeof siteName!=="undefined"){ return "http://m.jb51.net"+siteName; } } }; if(/Android|webOS|iPhone|iPad|Windows Phone|iPod|BlackBerry|SymbianOS|Nokia|Mobile/i.test(navigator.userAgent)){ var url=window.location.href; var pathname=window.location.pathname; if(url.indexOf("?mobile")<0){ try{ window.location.href=reWriteUrl(url); }catch(e){} } };})();</script>

注意,如果给搜索引擎看的话我们在文件头加入
<meta http-equiv="mobile-agent" content="format=xhtml; url=http://m.jb51.net" />
<meta http-equiv="mobile-agent" content="format=html5; url=http://m.jb51.net" />
意思是告诉搜索引擎移动蜘蛛抓取的是手机版本的.


更多文章

    上一篇:没有了 下一篇:没有了

相关文章

网站导航 | 快讯 | 资讯 | 手机 | 优化 | 系统 | 数码 | 网络通信 | 人工智能

  • 游戏 | 测评 | 专题 | 智车

    合作伙伴:

  • 友情链接(欢迎业界知名网站交换链接)申请友情

    

    声明:本站资源皆来自网络,如有侵权问题,请联系管理员处理!

    Copyright ©2020-2028快知站 版权所有 All rights reserved.

    闽ICP备20010713号-1 闽公网安备 35020602001684号