1,105,263 Community Members

Detect Browsers and Operating Systems using javascript

Member Avatar
tony75
Posting Whiz in Training
263 posts since Mar 2011
Reputation Points: 10 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi
Is ther anothe easy way to detect browser used and versions and Operating system via javascripts?

I appreciate your help

Member Avatar
LaxLoafer
Junior Poster
146 posts since Aug 2011
Reputation Points: 33 [?]
Q&As Helped to Solve: 22 [?]
Skill Endorsements: 18 [?]
 
0
 

The user-agent string contains the information you need. Using JavaScript you can access it through the browser's navigator object, e.g. navigator.userAgent.

Member Avatar
tony75
Posting Whiz in Training
263 posts since Mar 2011
Reputation Points: 10 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks sir
It seems not work for me

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Inform about user browser and Os</title>

<body>
<button id="display" onclick="myFunction()">Detect User browser and Operativ system</button>



<script>
    function myFunction()
    {
        var x = "User-agent header sent: " + navigator.userAgent;
        document.getElementById("demo").innerHTML=x;





    }
</script>
</body>
</html>
Member Avatar
LaxLoafer
Junior Poster
146 posts since Aug 2011
Reputation Points: 33 [?]
Q&As Helped to Solve: 22 [?]
Skill Endorsements: 18 [?]
 
0
 

Line 16, document.getElementById("demo") is returning null. There is no element with the ID demo.

Insert something like <p id="demo"></p> at line 11 and you should find it'll work.

Member Avatar
tony75
Posting Whiz in Training
263 posts since Mar 2011
Reputation Points: 10 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks Sir
Its work
What about detecting operation system?Have you any idea?

Member Avatar
JorgeM
IT Addict
6,381 posts since Dec 2011
Reputation Points: 567 [?]
Q&As Helped to Solve: 953 [?]
Skill Endorsements: 172 [?]
Moderator
Featured
Sponsor
 
0
 

You simply need to parse the string. So for example...

Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36

In this string, you can tell that the user is running Windows 8.1 because "Windows NT 6.3" indicates that the OS is Windows 8.1

Member Avatar
tony75
Posting Whiz in Training
263 posts since Mar 2011
Reputation Points: 10 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks Sir
Now Im understand it.

Question Answered as of 3 Months Ago by LaxLoafer and JorgeM
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: