0
我沒有手機/平板電腦兼容的佈局,所以當任何用戶來自移動/平板電腦/ Linux終端,我展示一個頁面「滾蛋」。但是,如果用戶來自PC瀏覽器IE老,IE邊緣,Safari瀏覽器,谷歌瀏覽器,Firefox,Opera,Midori等,那麼它是允許的。爲什麼JavaScript將Windows 10 pro,IE11視爲手機或平板電腦?
爲什麼我收到is_pc
爲false
甚至瀏覽器是PC和IE11?
window.onload = userAgentDetect;
var is_pc = true;
function userAgentDetect() {
if(window.navigator.userAgent.match(/Mobile/i)
|| window.navigator.userAgent.match(/iPhone/i)
|| window.navigator.userAgent.match(/iPod/i)
|| window.navigator.userAgent.match(/IEMobile/i)
|| window.navigator.userAgent.match(/Windows Phone/i)
|| window.navigator.userAgent.match(/Android/i)
|| window.navigator.userAgent.match(/BlackBerry/i)
|| window.navigator.userAgent.match(/webOS/i)) {
document.body.className+=' mobile';
is_pc = false;
get_out_from_here();
}
if(window.navigator.userAgent.match(/Tablet/i)
|| window.navigator.userAgent.match(/iPad/i)
|| window.navigator.userAgent.match(/Nexus 7/i)
|| window.navigator.userAgent.match(/Nexus 10/i)
|| window.navigator.userAgent.match(/KFAPWI/i)) {
document.body.className-=' mobile';
document.body.className+=' tablet';
is_pc = false;
get_out_from_here();
}
}
如果調試它,你應該得到你的答案...'的console.log(window.navigator.userAgent)' –
哪些錯誤與特徵檢測? /或響應式網站?檢查usageAgent是不好的做法,並且始終可能是僞造的。 – Keith
爵士,window.navigator.userAgent打印:'的Mozilla/5.0(Windows NT的10.0; WOW64;三叉戟/ 7.0;觸摸; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729 ; .NET CLR 3.5.30729;平板電腦2.0; RV:11.0)像Gecko' – YumYumYum