2016-10-13 5 views
0

私はモバイル/タブレット互換のレイアウトを持っていないので、モバイル/タブレット/ Linux端末から来たユーザーは、「出る」ページを表示します。しかし、ユーザーがPCのブラウザIEの古い、IEのエッジ、Safari、Google Chrome、Firefox、Opera、Midoriなどから来ている場合は、それは許可されています。JavaScriptがWindows 10をプロ、IE11をモバイルまたはタブレットとして扱うのはなぜですか?

なぜ私はis_pcfalseとしても、ブラウザは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(); 
    } 
} 
+0

あなたがそれをデバッグする場合は、あなたの答えを得る必要があります... 'にconsole.log(window.navigator.userAgent)' –

+0

いただきまし特徴検出と間違っていますか? /または反応しやすいウェブサイト?.. usageAgentをチェックすることは悪い習慣であることを意味し、とにかくいつでも偽装することができます。 – Keith

+0

Sir、window.navigator.userAgent、 'Mozilla/5.0(Windows NT 10.0; WOW64; Trident/7.0; Touch; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729 ; .NET CLR 3.5.30729; Tablet PC 2.0; rv:11.0)Geckoのように – YumYumYum

答えて

0

作業中です。

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(/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(); 
    } 
} 
関連する問題