2016-06-07 74 views
-1

只是一个普遍的问题。我正在开发一个将用于各种不同设备的网站。检查网站是否在某些设备上使用

是否可以检查网站运行在哪个设备上。 IOS,Android,桌面等与Javascript或Angular? OBS NOT JQUERY

对不起,不知道谷歌是什么,你能指点我的方向吗?

谢谢

+3

下面是答案如何检测浏览器的设备类型:http://stackoverflow.com/questions/3514784/什么是最好的方式来检测移动设备在jQuery –

回答

1

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()); 
    } 
}; 
+0

谢谢,我使用角JS来建立我的应用程序,所以我宁愿不使用JQuery。有没有办法做到这一点,而不使用JQuery? – andrea

+0

看到新的编辑 –

1

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.. 
} 
+0

你基本上复制了一个重复问题的答案[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) –