Blocking IE is definitely not best practice, but it's something in my requirements for an existing application. What's the most effective way to do that since conditional comments aren't available in IE 10? For IE 9 and below this will work:
<!--[if IE]>
<script type="text/javascript">
window.location = "/IEblocked.html";
</script>
<![endif]-->
Assuming there's a best practice JavaScript solution, what gotchas might I find? I'm wondering if there might be issues around the following:
- Order of events firing
iframe
elements that are beyond my control- Precedence of a JS solution in the context of other
<script>
tags - Scripts loaded via the
document.write('<script type="text/javascript" src="foo.js"></script>');
method.
I have a feeling a lot of folks might be compelled to shout out "use Modernizr" and "Are you crazy, don't put scripts in the DOM that way!", unfortunately the application is large and some enhancements are outside the scope at this point.
for future reference here is all the detections for ie in javascript
Well, IE is the only browser supporting client side VBScript.
So just add this to your pages: (except in IEblocked.html itself of course)
I know for a fact it's working in IE9 and below. This comment pretty much proves it's still working just fine in IE10 and as for the future I came across this blog post by Eric Lippert: Rumours of VBScript's Death Have Been Greatly Exaggerated which contains the following paragraph:
Although posted over 8 years ago, I strongly belive we still have long years of VBScript existence in the core of Windows, and future versions of Internet Explorer will keep using it.
To sum things up, I have contacted Eric directly and asked "How long will VBScript will be supported, as client side language, in Internet Explorer versions?". In response, he said:
He's no longer working in Microsoft so his answer is not official but it's the closest I can get and not years old blog post but directly from the source. All things considered, I can conclude that using the above code is going to work for many more years to come. :)
Your client is nuts. But if they're paying to do this, then.... meh, whatever.
If you're using jQuery, it provides a browser detection feature. It is deprecated, so you may want to avoid using the latest versions, but it does work:
If you're not using jQuery, or if you prefer not to use deprecated features, you can do it by:
Parsing the User Agent string:
Using Javascript conditional comments (which I believe are still supported):
Hope that helps.