How can we get the device information using JavaScript?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 11

How can we get the device information using JavaScript??

What I want is to get the details of device (name of device) and display the device name in a code...

10th Jul 2018, 10:18 AM
$hardul B
$hardul B - avatar
14 Answers
+ 10
$hardul Birje I struggled for this myself for one project to detect unique users for a polling app, I trashed that project. We can only have the info that browser provides us, so there are few APIs to access certain device infos through js from pure web apps like -Page visibility -user online or not -ambient light info from sensor -battery status But none for device name 😪 But there are few libraries that can detect whether a device is phone, iPad, or pc. Like this one http://blog.mobileesp.com/ If we want device info then we have to rely on native apps ( apps that are installed on phones) Regarding the issue of inconsistent results from navigator.UserAgent string, there's a good library that does an awesome job on detecting the browser used by device. (Not sure how it does today) in my code I am picking only those info that were used to detect issues on SL codes, dig deep in library to find more info. https://code.sololearn.com/W4vC0w43yqNQ/?ref=app
2nd Jan 2019, 6:03 PM
Morpheus
Morpheus - avatar
+ 8
Thank you so much EnRico Lam ..
10th Jul 2018, 5:17 PM
$hardul B
$hardul B - avatar
+ 6
EnRico Lam i don't have knowledge of PHP... well device sniffing sounds something bad... Well I just wanted to display device info to the user itself.. I don't mean to do something bad 😅
10th Jul 2018, 4:52 PM
$hardul B
$hardul B - avatar
+ 6
code learner the code is somewhat related as it gets battery info... Thank you ☺️
10th Jul 2018, 4:54 PM
$hardul B
$hardul B - avatar
+ 5
It is difficult to accurately determine all information about the user since many different browsers or devices can report the same results on JavaScript. This might help. https://www.w3schools.com/js/js_window_navigator.asp
10th Jul 2018, 10:46 AM
James
James - avatar
+ 4
Thank you for your answers James and Chilly_Vanilly
10th Jul 2018, 2:55 PM
$hardul B
$hardul B - avatar
+ 3
well, I know what you want is javascript, but if php is an avaliable option to you, you may give mobiledetect a try, and btw, what you are trying to do, has a name, called "device sniffing".
10th Jul 2018, 3:56 PM
EnRico Lam
EnRico Lam - avatar
+ 3
I don't know the answer for your question, but it reminds me of this code :- https://code.sololearn.com/WEFAMP33GHDg/?ref=app
10th Jul 2018, 4:48 PM
code learner
code learner - avatar
+ 3
the code based on feature detection which try to detect browser specific abilities and browsers' custom features and guess what browser is it based on the result, but keep in mind that the user is always capable of keeping you out from knowing which browser they are using.
10th Jul 2018, 5:01 PM
EnRico Lam
EnRico Lam - avatar
+ 2
and I found this, not perfect, but close to what you want
10th Jul 2018, 5:02 PM
EnRico Lam
EnRico Lam - avatar
10th Jul 2018, 5:02 PM
EnRico Lam
EnRico Lam - avatar
+ 2
a javascript version of my favorite ,"device -detection.php"
10th Jul 2018, 5:03 PM
EnRico Lam
EnRico Lam - avatar
+ 2
Thank you Morpheus sir! 👍👍
2nd Jan 2019, 6:19 PM
$hardul B
$hardul B - avatar
+ 1
I do have half of a piece of code of how to (more) accurately detect browser types, but not user device model. https://code.sololearn.com/Wya8Y5NrESqh/?ref=app
10th Jul 2018, 4:58 PM
EnRico Lam
EnRico Lam - avatar