只是一個普遍的問題。我正在開發一個將用於各種不同設備的網站。檢查網站是否在某些設備上使用
是否可以檢查網站運行在哪個設備上。 IOS,Android,桌面等與Javascript或Angular? OBS NOT JQUERY
對不起,不知道谷歌是什麼,你能指點我的方向嗎?
謝謝
只是一個普遍的問題。我正在開發一個將用於各種不同設備的網站。檢查網站是否在某些設備上使用
是否可以檢查網站運行在哪個設備上。 IOS,Android,桌面等與Javascript或Angular? OBS NOT JQUERY
對不起,不知道谷歌是什麼,你能指點我的方向嗎?
謝謝
What is the best way to detect a mobile device in jQuery?
這被問同樣的問題。你可以爲此使用JQuery。
編輯:
試試這個。
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
謝謝,我使用角JS來建立我的應用程序,所以我寧願不使用JQuery。有沒有辦法做到這一點,而不使用JQuery? – andrea
看到新的編輯 –
What is the best way to detect a mobile device in jQuery?
使用此只使用JavaScript檢測設備:
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
// some code..
}
你基本上覆制了一個重複問題的答案[link](http://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device在jQuery中),你應該參考原始答案...就像@ [Dhaval Soni](http://stackoverflow.com/users/4829473/dhaval-soni) –
下面是答案如何檢測瀏覽器的設備類型:http://stackoverflow.com/questions/3514784/什麼是最好的方式來檢測移動設備在jQuery –