標籤:
針對不同用戶端下載連結的頁面響應樣式不一樣,更人性點而已//匹配用戶端類型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判斷用戶端的類型