+ 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...
14 Réponses
+ 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
+ 8
Thank you so much EnRico Lam ..
+ 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 😅
+ 6
code learner the code is somewhat related as it gets battery info... Thank you ☺️
+ 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
+ 4
Thank you for your answers James and Chilly_Vanilly
+ 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".
+ 3
I don't know the answer for your question, but it reminds me of this code :-
https://code.sololearn.com/WEFAMP33GHDg/?ref=app
+ 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.
+ 2
and I found this, not perfect, but close to what you want
+ 2
a javascript version of my favorite ,"device -detection.php"
+ 2
Thank you Morpheus sir! 👍👍
+ 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