|
Help
CodingForums Partners
This is a
![]() |
|
| Scheme | Description |
|---|---|
| document.getElementById | Detects modern browsers in general, which covers IE5+, Firefox1+, and Opera7+ |
| window.getComputedStyle | Detects Firefox1+ and Opera 8+ |
| Array.every | Detects Firefox1.5+ (method detection) |
| window.Iterator | Detects Firefox2+ |
| document.all | Detects IE4+ |
| window.attachEvent | Detects IE5+ |
| window.createPopup | Detects IE5.5+ |
| document.compatMode && document.all | Detects IE6+ |
| window.XMLHttpRequest | Detects IE7, Firefox1+, and Opera8+ |
| window.XMLHttpRequest && document.all | Detects IE7. Note: Will fail if visitor explicitly disables native xmlHTTPRequest support (under Toolbar-> Internet Options-> Advanced) |
| document.documentElement && typeof document.documentElement.style.maxHeight!="undefined" | Another way of detecting IE7 that is more reliable than the above. |
| window.opera | Detects 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!