2016-10-13 1 views
0

Ich habe kein Handy/Tablet-kompatibles Layout, also wenn ein Benutzer von einem mobilen/Tablet/Linux-Terminal kommt, zeige ich eine Seite "raus". Aber wenn der Benutzer kommt von einem PC Browser IE alt, IE Rand, Safari, Google Chrome, Firefox, Opera, Midori usw. usw. Dann ist es erlaubt.Warum behandelt JavaScript Windows 10, IE11 als Handy oder Tablet?

Warum bekomme ich is_pc als false sogar der Browser war PC und 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

Wenn Sie es debuggen, sollten Sie Ihre Antwort erhalten ... 'console.log (window.navigator.userAgent)' –

+0

Was stimmt nicht mit Feature-Erkennung?/oder Responsive Website? .. Überprüfung der VerwendungAgent soll schlechte Praxis sein und kann sowieso immer gefälscht werden. – Keith

+0

Sir, window.navigator.userAgent druckt: 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; Berühren; .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) wie Gecko' – YumYumYum

Antwort

0

Arbeiten.

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(); 
    } 
} 
Verwandte Themen