Tuesday, May 7, 2013

Detect user agent using javascript

To detect user agent in JavaScript, simple read navigator.userAgent.

Detect user agent using javascript


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mobile-Web-App: Detect Browser</title>
<script type="text/javascript">
 
function detectbrowser(){
info = "<p><b>Browser info: </b></p>"
+ "<p>user agent: " + navigator.userAgent + "</p>";
 
document.getElementById("browserinfo").innerHTML=info;
}
 
</script>
</head>
<body onload="detectbrowser();">
<h1>Mobile-Web-App: Javascript Exercise - Detect User Agent</h1>
<div id="browserinfo"></div>
</body>
</html>


No comments:

Post a Comment