• js判断是否是移动端 访问移动端网址


    1以下为代码,可放置在网站foot底部文件,或者haead顶部文件,建议将代码放在网站顶部,这样可以实现手机访问立即跳转!

    <script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script><script type="text/javascript">uaredirect("http://m.jiuquan.cc");</script>

    将代码网址部分改成你网站的手机网址就Ok,当然可以是任意网址!

    这应该就是传说中的WAP自动跳转吧!

    2.

    <script>
    
        if(navigator.platform.indexOf('Win32')!=-1){ 
    
        //pc
    
            //window.location.href="电脑网址";
    
         }else{ 
    
       //shouji
    
            window.location.href="手机网址";
    
          } 
    
    </script>

    3.

    <script type="text/javascript">
    
    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= '手机网站地址'; 
    
    } else { 
    
    window.location= '电脑网站地址'; 
    
    } 
    
    } 
    
    browserRedirect(); 
    
    </script>

    4.

    <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; 
    
    //alert(mobileAgent[i]); 
    
    location.href = '手机网址';
    
    break; } } 
    
    </script>
  • 相关阅读:
    170815、redis3.0安装配置
    170814、Java使用gzip压缩文件、还原文件
    170811、Java获取jdk系统环境变量
    170810、spring+springmvc+Interceptor+jwt+redis实现sso单点登录
    加密概述
    软件测试入门第02天:基础理论知识
    软件测试入门第01天:综述
    【心路历程】永远热泪盈眶
    Linux部署Django:报错 nohup: ignoring input and appending output to ‘nohup.out’
    【WEB】jQuery 判断复选框是否选中
  • 原文地址:https://www.cnblogs.com/zhangrenjie/p/5711969.html
Copyright © 2020-2023  润新知