移动端与pc端的自动识别与跳转

	function judgePcAndMobile(){
      // //alert("目前的地址:"+location.href)
      var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", 
      "webmate", "bada", "nokia", "lg", "ucweb", "skyfire");
      var browser = navigator.userAgent.toLowerCase();
      // //alert(browser)
      console.log(browser.match('android'))
      var isMobile = false;
      if (
        browser.match('iphone') !== null || browser.match('ipod') !== null || browser.match('ipad') !== null || 
        browser.match('android') !== null || browser.match('mobile') !== null || browser.match('blackberry') !== null || browser.match('webos') !== null || 
        browser.match('incognito') !== null ||browser.match('webmate') !== null ||browser.match('nokia') !== null ||
        browser.match('lg') !== null ||browser.match('ucweb') !== null || browser.match('skyfire') !== null 
        )
      {
        // alert("是否进入判断是手机")
        isMobile = true;alert(mobileAgent[i]);
        if(location.href.match('网址') !== null){
          //alert("我已经是手机端网址了")
          return 
        }else{
          //alert("跳转手机端网址手机端网址了")
          location.href = '网址';
          return 
        }
      }else{
        if(location.href.match('网址') !== null){
          //alert("我已经是pc端网址了")
          return 
        }else{
          location.href = '网址';
          //alert("跳转pc端网址了")
          return 
        }
      }
    }
    judgePcAndMobile()
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值