簡體   English   中英

更新Windows 8移動設備的設備檢測代碼-手機和Surface X

[英]Updating device detection code for Windows 8 mobile devices - phones and Surface X

我以前曾使用附帶的代碼來檢測移動設備,但是(對於顯而易見的原因)它不適用於Windows 8移動電話和任何Surface版本。 我不知道Windows 8手機和Surface的正確userAgent。 為了能夠檢測Surface或Windows 8手機,需要進行哪些更改? 任何幫助將不勝感激 ! 在此先感謝一噸。

function detect() {
var uagent = navigator.userAgent.toLowerCase();
var mobile = false;
var search_strings = [
"iphone",
"ipod",
"ipad",
"series60",
"windows ce",
"windows7phone",
"w7p",
"windows8phone",
"w8p",
"blackberry","
];
for (i in search_strings) {
    if (uagent.search(search_strings[i]) > -1)
        mobile = true;
    }
            return mobile;
}

if (detect()){
    window.location = "mobile";
}

使用RegExpUser Agent進行搜索,這涵蓋了99%的現代設備:

/Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Symbian|Opera\sM(obi|ini)|Blazer|Dolfin|Dolphin|UCBrowser/.test(navigator.userAgent);

您也可以使用服務wurfl.io它會在javascript中返回一個對象,標記是否為device mobile。 它使用wurfl雲和數千個已知的UA。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM