Take the 2-minute tour ×

Possible Duplicate:
Best way to detect that HTML5 <canvas> is not supported

Now that $.browser is being taken out of jQuery in favor of $.support, how would I detect IE8 with jQuery, or with plain javascript?

if ($.browser.msie  && parseInt($.browser.version, 10) === 8) {

Sorry, but HTML will not work for me. So I can not do this:

<!--[if IE 8]>
<script type="text/javascript">
    ie = 8;

Specifically, I am looking to do work with the canvas tag and IE8 does not support canvas, but jQuery.support does not detect for canvas support.

share|improve this question
The whole reason for doing this is that you shouldn't need to test for IE8. Why are you trying to? –  lonesomeday Jul 6 '12 at 21:33
That link doesn't say its being deprecated, it is just explaining that feature detection is more recommended than browser detection. –  Tyrsius Jul 6 '12 at 21:33
what do you need to do in IE that is so impossible? the whole point of using jquery is to forget which browser you are working on –  Ibu Jul 6 '12 at 21:34
@BishopZ stackoverflow.com/questions/2745432/… –  lonesomeday Jul 6 '12 at 21:40
Sometimes people ask the wrong question. This question could have been: "How do I look for a number in a string that is greater than a certain number using a regex?" Why? Because I need to look at a browser agent string. "Why?" Because I need to detect if the browser is greater than IE8. Why? "Because I want to see if canvas is supported." Ah ha! So what you REALLY want to do is see if canvas is supported. Asking for help with your ORIGINAL problem is important. Not to pick on the OP too much :) –  aquinas Jul 6 '12 at 21:48
show 5 more comments

marked as duplicate by Ibu, Esailija, Colin, Brandon Boone, Evan Mulawski Jul 7 '12 at 0:45


2 Answers

up vote 8 down vote accepted

Test for the feature instead:

var el = document.createElement('canvas');
if (el.getContext && el.getContext('2d')) {
    // canvas supported 


As in the link suggested in comments by Brandon Boone, here's a function that does it:

function isCanvasSupported(){
  var elem = document.createElement('canvas');
  return !!(elem.getContext && elem.getContext('2d'));
share|improve this answer
@BrandonBoone: Thanks, added –  Andre Jul 6 '12 at 21:47
add comment

If jQuery doesn't do what you need, I suggest using Modernizr for feature detection instead.

The other option, of course, is simply to stick with the older version of jQuery, before $.browser was deprecated. It still works just as well as it always did; no-one is forcing you to upgrade to the latest version.

Finally, you state that you can't edit the HTML so you can't use conditional comments. However, it's worth pointing out that IE also supports a Javascript equivalent to conditional comments. I would assume that you would be able to use this feature.

The following code is taken from Wikipedia - adapt it as necessary:


  @if (@_jscript_version == 10)
    document.write("You are using IE10");

  @elif (@_jscript_version == 9)
    document.write("You are using IE9");

  @elif (@_jscript_version == 5.8)
    document.write("You are using IE8");

  @elif (@_jscript_version == 5.7 && window.XMLHttpRequest)
    document.write("You are using IE7");

  @elif (@_jscript_version == 5.6 || (@_jscript_version == 5.7 && !window.XMLHttpRequest))
    document.write("You are using IE6");

  @elif (@_jscript_version == 5.5)
    document.write("You are using IE5.5");

    document.write("You are using IE5 or older");


share|improve this answer
Modernizer is great and what I typically use, but it is not installed on this project. Thanks for the comment. –  BishopZ Jul 6 '12 at 21:45
@BishopZ - I've added other alternative solutions to the answer. –  Spudley Jul 6 '12 at 21:52
wow, very interesting, thank you! –  BishopZ Jul 6 '12 at 22:15
add comment
