-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect.html
More file actions
57 lines (46 loc) · 1.48 KB
/
detect.html
File metadata and controls
57 lines (46 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!doctype html>
<html>
<head>
<title>Simple Javascript Browser Detection</title>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css"/>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
/*!
* Simple Detect class for Device and Browser
*
* Author: John Rocela 2012 <me@iamjamoy.com>
*/
var detect = {
ua: navigator.userAgent || navigator.vendor || window.opera,
is: function(val, list) {
for (var i = 0; i < list.length; i++) {
if (this.ua.indexOf(list[i]) != -1) return list[i];
}
return "Unknown";
},
device: function(val) {
if (val) return (this.ua.indexOf(val) != -1) ? true: false;
return this.is(val, ['Mac','Windows','iPhone/iPod', 'Android'])
},
browser: function(val) {
if (val) return (this.ua.indexOf(val) != -1) ? true: false;
return this.is(val, ['Chrome','Safari','Opera','Firefox', 'MSIE'])
}
}
jQuery(function(){
$('#device').html(detect.device());
})
</script>
<style>
p { line-height: 19px; margin: 10px 0; }
</style>
</head>
<body>
<div style="padding:20px;">
<h1>Simple Javascript isBrowser() snippet</h1>
<p>Here is an example of the <code>isBrowser()</code> method. try it on different browser to see the result.</p>
<p>You are using <span id="device" style="font-weight:bold;"></span></p>
<p style="margin-top:50px;">Code Love © Jamoy. iamjamoy.com</p>
</div>
</body>
</html>