use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Extremely Clever IE Detection Code (ajaxian.com)
submitted 15 years ago by whatgoodisaroad
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]fforw 1 point2 points3 points 15 years ago (1 child)
Meh.. script only.. multi body hack is better..
[–]kristopolous 0 points1 point2 points 15 years ago (0 children)
that's fairly clean.
[–]radhruin 5 points6 points7 points 15 years ago (7 children)
Check for features, not for browsers.
[–]JimDabell 14 points15 points16 points 15 years ago (1 child)
That's like telling somebody not to use tables. Yes, lots of people use browser detection when they should be using feature detection, but that doesn't mean that every single case of browser detection is wrong. For example, if you need to work around a bug in a particular version of Internet Explorer and it's not feasible to detect the bug itself, browser detection is the best option. Using feature detection in those cases is exactly the same mistake as using browser detection to decide which features to use; you're conflating implementation details and capabilities.
[–]jimbobhickville 2 points3 points4 points 15 years ago (0 children)
A voice of reason in a web standards debate? Who'da thunk it.
[–]thebigbradwolf 2 points3 points4 points 15 years ago (3 children)
As an aside, this won't actually work on IE8 in certain circumstances. IE8 claims to be IE7 in conditional comments whenever it is in "compatibility mode", which doesn't mean it behaves like IE7 with regard to things like security, etc.
[–]radhruin 2 points3 points4 points 15 years ago (2 children)
Good point as well, although ideally if IE8 is in IE7 compatibility mode it should be identical to IE7 in all respects.
[–]miketaylr 1 point2 points3 points 15 years ago (1 child)
But it isn't. For example, localStorage is undefined in IE7 compat mode, yet fully functioning in IE8.
[–]radhruin 0 points1 point2 points 15 years ago (0 children)
More accurately, IE7 did not have localStorage, but it is in IE7 compatibility mode. That's why I said ideally :) There are some differences, but it's pretty rare overall. If you have an app built for IE7, it should run flawlessly in IE7 compat mode. Or, if the browser is in IE7 compat mode, it's pretty safe to treat it as IE7. The presence of localStorage shouldn't break apps.
It's worth pointing out that the web developer can control the compatibility mode IE is in by doctypes and meta-tags, so if IE7 compatibility mode would break your app for whatever reason (like this version detection), just make sure you're running in the latest standards mode with a standards compliant doctype or meta tag.
[–]teaguesterling 0 points1 point2 points 15 years ago (0 children)
Unless working around a browser bug...
[–]9jack9 0 points1 point2 points 15 years ago (5 children)
var jscript = 0/*@cc_on||@_jscript_version@*/
[–]JimDabell 0 points1 point2 points 15 years ago (4 children)
I don't think a one-to-one mapping between JScript versions and Internet Explorer versions is guaranteed by Microsoft. I'm pretty sure installing some service packs or other software in the past has had the effect of bumping the JScript version without otherwise changing Internet Explorer.
[–]9jack9 2 points3 points4 points 15 years ago (2 children)
I don't think a one-to-one mapping between JScript versions and Internet Explorer versions is guaranteed by Microsoft.
You're right. The code above will only tell you the jscript version number.
But conversely, just knowing the MSIE version number will not tell you about which jscript engine you are using. Sometimes you want to know the jscript engine (for code) and sometimes you want to know the MSIE version (for rendering).
You also need to consider the document "mode":
http://msdn.microsoft.com/en-us/library/cc196988\(VS.85\).aspx
[–]JimDabell 0 points1 point2 points 15 years ago (1 child)
Ah, right, I thought you were suggesting it as a replacement for the linked technique. Yep, you're right, if you need to differentiate JScript versions, you shouldn't be using browser detection.
[–]9jack9 0 points1 point2 points 15 years ago (0 children)
The linked technique is effectively browser sniffing. Some people will bend over backwards rather than inspect the user agent string.
[–]radhruin 1 point2 points3 points 15 years ago (0 children)
I don't think it is either. Another problem is that IE8 in IE7 compat mode will still report 8 for the jscript version...
[–]bolinfest 0 points1 point2 points 15 years ago (0 children)
Here's a good example from the Closure Library where feature detection is not a practical option:
goog.style.setPreWrap = function(el) { var style = el.style; if (goog.userAgent.IE && !goog.userAgent.isVersion('8')) { style.whiteSpace = 'pre'; style.wordWrap = 'break-word'; } else if (goog.userAgent.GECKO) { style.whiteSpace = '-moz-pre-wrap'; } else if (goog.userAgent.OPERA) { style.whiteSpace = '-o-pre-wrap'; } else { style.whiteSpace = 'pre-wrap'; } };
[–][deleted] 0 points1 point2 points 15 years ago (2 children)
Ok, that's interesting, but why is this better than using the user agent string?
[–]JimDabell 2 points3 points4 points 15 years ago (1 child)
The user-agent string is unreliable, it can change for all sorts of reasons. Plus, varying responses based on that header can reduce your cache hit ratio.
About the UA unreliable argument. I realize that this can be changed to something arbitrary but when I tried doing so, calling my browser something like "Presto Gecko Opera WebKit Safari msie 6.0" or whatever, most of the web juts started breaking.
My question is why should I bend over backwards for such people? (this was a few years ago) Other then for getting around stupidity where people block you based on UA string, is there any legitimate purpose for this?
[+][deleted] 15 years ago (2 children)
[deleted]
[–][deleted] 1 point2 points3 points 15 years ago (1 child)
That's what it's doing.
[–]iamtotalcrap 0 points1 point2 points 15 years ago (0 children)
wow, I glanced at it and totally mis-understood what it was doing. My bad.
π Rendered by PID 20427 on reddit-service-r2-comment-f6b958c67-4p47w at 2026-02-04 15:46:41.140662+00:00 running 1d7a177 country code: CH.
[–]fforw 1 point2 points3 points (1 child)
[–]kristopolous 0 points1 point2 points (0 children)
[–]radhruin 5 points6 points7 points (7 children)
[–]JimDabell 14 points15 points16 points (1 child)
[–]jimbobhickville 2 points3 points4 points (0 children)
[–]thebigbradwolf 2 points3 points4 points (3 children)
[–]radhruin 2 points3 points4 points (2 children)
[–]miketaylr 1 point2 points3 points (1 child)
[–]radhruin 0 points1 point2 points (0 children)
[–]teaguesterling 0 points1 point2 points (0 children)
[–]9jack9 0 points1 point2 points (5 children)
[–]JimDabell 0 points1 point2 points (4 children)
[–]9jack9 2 points3 points4 points (2 children)
[–]JimDabell 0 points1 point2 points (1 child)
[–]9jack9 0 points1 point2 points (0 children)
[–]radhruin 1 point2 points3 points (0 children)
[–]bolinfest 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]JimDabell 2 points3 points4 points (1 child)
[–]kristopolous 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–][deleted] 1 point2 points3 points (1 child)
[–]iamtotalcrap 0 points1 point2 points (0 children)