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

前端之家收集整理的这篇文章主要介绍了js判断手机访问或者PC的几个例子(常用于手机跳转)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

例子一

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='//www.jb51.cc'; }else{ //window.location.href='http://m.jb51.cc'; } } $(function(){ browserRedirect(); });

例子2

注意,如果给搜索引擎看的话我们在文件头加入 意思是告诉搜索引擎移动蜘蛛抓取的是手机版本的.

猜你在找的JavaScript相关文章