標籤:console back else ack navig width 其他 agent logs
判斷終端並對相應的終端進行不同處理方法(函數)
$("#btn_download").click(function () { var u = navigator.userAgent; var isAndroid = u.indexOf(‘Android‘) > -1 || u.indexOf(‘Adr‘) > -1; //android終端 var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios終端 $("#lucencyBg").show(); if (isAndroid) { //android終端處理函數 alert(‘是否是Android:‘+isAndroid); }else if(isiOS){ //ios終端處理函數 alert(‘是否是iOS:‘+isiOS); }else{ alert("其他瀏覽器"); } });
附:jQuery處理背景圖片不能撐滿螢幕:
$("#_main").height(window.innerHeight); //兩種方法可選,可根據需要選擇 //window.screen.height //window.innerHeight //console.log(window.screen.height);
這樣css代碼就不用寫高度了,但是要加上幾句css:
#_main{ width: 100%; background: url("../images/QRBg.png") 0 0 no-repeat; /*需要添加下面的代碼*/ background-size: 100% auto; display: flex; justify-content: center;}
jQuery 判斷終端是IOS還是Android / jQuery處理背景圖片不能撐滿螢幕