|
Help
CodingForums Partners
This is a
![]() |
|
| Scheme | Detects |
|---|---|
| document.getElementById | Firefox1+, IE5+, Opera7+, Safari, and most modern browsers in general. |
| window.getComputedStyle | Firefox1+ and Opera 8+, and Safari 2+ |
| window.globalStorage | Firefox2+ |
| window.globalStorage && window.postMessage | Firefox3+ |
| document.getElementsByClassName | Firefox3+ and Opera 9.5+, and Safari 3+ |
| document.querySelector | Firefox3.5+, IE8+ (in standards compliant mode only), Opera9.5+, and Safari 3+ |
| document.all | IE4+ |
| window.attachEvent | IE5+ |
| window.createPopup | IE5.5+ |
| document.compatMode && document.all | IE6+ |
| window.XMLHttpRequest | IE7+, Firefox1+, and Opera8+ |
| window.XMLHttpRequest && document.all or: document.documentElement && typeof document.documentElement.style.maxHeight!="undefined" |
IE7+ Note: First scheme will fail if visitor explicitly disables native xmlHTTPRequest support (under Toolbar-> Internet Options-> Advanced). The second one will not. |
| XDomainRequest | IE8+ |
| window.opera | Opera (any version) |
* Since Opera by default also identifies itself as IE (apart from Opera), with support for many of IE's proprietary objects, the IE detection schemes above will also return true for Opera. Use "window.opera" in combination to filter out Opera browsers.
It's important to mention that object detection's chief purpose is to help you detect within your script whether the browser supports a particular object/method/property before using it, not browser detection. As the later it may be convenient over probing the Navigator object, but is only as reliable as your understanding of which objects are supported in which browsers. In other words, it's not a 100% reliable way of sniffing out the user's browser. Having said that, the below uses object detection to test for IE7:
<script type="text/javascript">
if (document.documentElement && typeof document.documentElement.style.maxHeight!="undefined")
alert("You're using IE7")
</script>
Again object detection is really about feature detection. It detects whether your browser supports the feature your script intends to use and manipulate. For the lazy, that will substitute for browser detection just fine!