jquery判斷用戶端的類型

來源:互聯網
上載者:User

標籤:

針對不同用戶端下載連結的頁面響應樣式不一樣,更人性點而已//匹配用戶端類型var isAndroid = navigator.userAgent.toLowerCase().match(/android/i) == "android";var isIphone = navigator.userAgent.toLowerCase().match(/iphone os/i) == "iphone os";var isIpad = navigator.userAgent.toLowerCase().match(/ipad/i) == "ipad";var isWin = navigator.userAgent.toLowerCase().match(/windows phone/i) == "windows phone";var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");//定義幾個函數,擷取url中的get參數 (function($) {  $.extend({     urlGet:function()    {      var aQuery = window.location.href.split("?"); //取得Get參數      var aGET = new Array();      if(aQuery.length > 1)      {        var aBuf = aQuery[1].split("&");        for(var i=0, iLoop = aBuf.length; i<iLoop; i++)        {          var aTmp = aBuf[i].split("="); //分離key與Value          aGET[aTmp[0]] = aTmp[1];        }      }      return aGET;    }  })})(jQuery);$(document).ready(function(){        var curr_url = window.location.href;        var host = window.location.host;        var GET = $.urlGet();         var curr_url = GET[‘url_download‘];        if(isAndroid || isIpad || isIphone || isWin){       //手機端的樣子            $(".addthis_sharing_toolbox").show();            //ajax請求,匹配參數獲得傳回值            if(curr_url.indexOf(".exe")!=-1||curr_url.indexOf(".dmg")!=-1){                $.ajax({                         url:‘http://‘+host+‘/index.php/Index/mobile_url‘,                         type:‘post‘,                         data:{url:curr_url},                         async : true,                      error:function(){                             alert(‘error‘);                         },                    success:function(data){              //只是一些樣式的控制,不用看                        $(".box1").show();                        $(".box2").hide();                        $(".addthis_sharing_toolbox").show();                        $(".discountCode").show();                        var json = eval(‘(‘ + data + ‘)‘);                        $("#win_price").html(json.win_price);                        $("#mac_price").html(json.mac_price);                        $("#win_btn").attr(‘href‘,json.win_buy);                        $("#mac_btn").attr(‘href‘,json.mac_buy);                        $("#share_code").attr(‘data-url‘,json.skip_url);                        $("#share_code").attr(‘data-title‘,json.skip_title);                    }                });            }        }else{       //pc端的樣子,樣式的控制不用看            $(".box1").hide();            $(".box2").show();            $("#pc_download").attr(‘href‘,curr_url);            location.href=curr_url;        }

 

jquery判斷用戶端的類型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.