JS判断手机端跳转代码

模板网 2015-05-12

JS判断手机端跳转代码

复制代码 代码如下:
var browser={
    versions:function(){ 
           var u = navigator.userAgent, app = navigator.appVersion;
           return {//移动终端浏览器版本信息 
                trident: u.indexOf('Trident') > -1, //IE内核
                Opera: u.indexOf('Opera') > -1, //opera内核  //Presto
                Series: u.indexOf('Series') > -1, //opera内核  塞班手机
                webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/) && u.indexOf('QIHU') && u.indexOf('Chrome') && u.indexOf('; U;')>-1, //是否为移动终端   去掉||!!u.match(/AppleWebKit/ 否则在pc上用safari,google打开也会跳到手机站。
                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
                iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
                iPad: u.indexOf('iPad') > -1, //是否iPad
                webApp: u.indexOf('Safari') == -1, //是否web应该程序,没有头部与底部
ua:u 
            };
         }(),
         language:(navigator.browserLanguage || navigator.language).toLowerCase()
 
if(((browser.versions.mobile) || (browser.versions.android) ||(browser.versions.Series)) && !browser.versions.iPad){
  this.location = "http://m.baidu.com";//判断是手机
}else if(browser.versions.iPad){
  this.location = "http://www.baidu.com"; //判断是ipad
}

相关文章

  1. 最新获取访客QQ接口—20140915

    最新获取访客QQ接口,分析某网站代码得到的最新获取访客QQ的接口,接口地址: http://x.pet.qq.com/vip_platform?cmd=entercallback=aaa 复制代码 代码如下: script window.www120mubancom = scriptfunction aaa(obj){parent.qq(obj);}\/scriptscript src=htt

  2. 使用新浪获取IP所在地接口做网站跳转

    使用新浪获取IP接口做网站跳转 title使用新浪获取IP接口做网站跳转/title !--引用新浪IP获取接口-- script type=text/javascript src=http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js/script !--引用新浪IP获取接口-- script type=text/javas

  3. JS判断手机端跳转代码

    JS判断手机端跳转代码 复制代码 代码如下: var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return {//移动终端浏览器版本信息 trident: u.indexOf(Trident) -1, //IE内核 Opera: u.indexOf(Opera) -1, //ope

  4. JS 文本框默认提示信息点击清空

    JS 文本框默认提示信息点击清空,关键的代码。 复制代码 代码如下: onfocus=if(this.value==this.defaultValue){this.value=;}; onblur=if(this.value==){this.value=this.defaultValue;} type=text 效果截图:

  5. 从腾讯网提取的判断手机端访问跳转代码

    从腾讯网提取的判断手机端访问跳转代码,使用了一个正则表达式来判断浏览器的navigator.userAgent标志,来确认访问终端,从而做出相应的操作。 代码简单,注释详细,容易理解。 复制代码 代码如下: script type=text/javascript if(/Android|Windows Phone|w

随机推荐

  1. 最新获取访客QQ接口—20140915

    最新获取访客QQ接口,分析某网站代码得到的最新获取访客QQ的接口,接口地址: http://x.pet.qq.com/vip_platform?cmd=entercallback=aaa 复制代码 代码如下: script window.www120mubancom = scriptfunction aaa(obj){parent.qq(obj);}\/scriptscript src=htt

  2. 使用新浪获取IP所在地接口做网站跳转

    使用新浪获取IP接口做网站跳转 title使用新浪获取IP接口做网站跳转/title !--引用新浪IP获取接口-- script type=text/javascript src=http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js/script !--引用新浪IP获取接口-- script type=text/javas

  3. JS判断手机端跳转代码

    JS判断手机端跳转代码 复制代码 代码如下: var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return {//移动终端浏览器版本信息 trident: u.indexOf(Trident) -1, //IE内核 Opera: u.indexOf(Opera) -1, //ope

  4. JS 文本框默认提示信息点击清空

    JS 文本框默认提示信息点击清空,关键的代码。 复制代码 代码如下: onfocus=if(this.value==this.defaultValue){this.value=;}; onblur=if(this.value==){this.value=this.defaultValue;} type=text 效果截图:

  5. 从腾讯网提取的判断手机端访问跳转代码

    从腾讯网提取的判断手机端访问跳转代码,使用了一个正则表达式来判断浏览器的navigator.userAgent标志,来确认访问终端,从而做出相应的操作。 代码简单,注释详细,容易理解。 复制代码 代码如下: script type=text/javascript if(/Android|Windows Phone|w