Skip to content

Instantly share code, notes, and snippets.

@anhr
Forked from jalbertbowden/ie-6-9-detect.js
Last active August 29, 2015 14:26

Revisions

  1. anhr revised this gist Aug 4, 2015. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion ie-mobile-detect.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,9 @@
    // The same thing but for IE Mobile instead.
    // I see "Unable to get property '1' of undefined or null reference"
    // because
    // /IEMobile\/(\d+\.?(\d+)?)/.exec( navigator.userAgent ) is null
    // if "IEMobile" string is not exists in the navigator.userAgent.
    // I have used a code below for resolving of problem:

    var ieMobile = ( !! window.ActiveXObject && +( /IEMobile\/(\d+\.?(\d+)?)/.exec( navigator.userAgent )[1] ) ) || NaN;
    var ieMobile = /IEMobile\/(\d+\.?(\d+)?)/.exec( navigator.userAgent );
    ieMobile = ( !! window.ActiveXObject && ieMobile && (ieMobile.length >= 2) && +( ieMobile[1] ) ) || NaN;
  2. @jalbertbowden jalbertbowden renamed this gist Mar 16, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @jalbertbowden jalbertbowden revised this gist Mar 16, 2013. 3 changed files with 20 additions and 12 deletions.
    15 changes: 13 additions & 2 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,18 @@
    // ie === 6 // IE6
    // ie > 7 // IE8, IE9 ...
    // ie < 9 // Anything less than IE9
    // ----------------------------------------------------------

    // script needs to be wrapped on conditional comments to exclude > ie9
    // appends class of "ieX" where X is version number, to document's html element
    // ie8 demo http://dev.bowdenweb.com/ua/browsers/ie/ie8-detection.html
    // ie9 demo http://dev.bowdenweb.com/ua/browsers/ie/ie9-detection.html

    var ie = ( !!window.ActiveXObject && +( /msie\s(\d+)/i.exec( navigator.userAgent )[1] ) ) || NaN;
    if (ie === 6) {
    document.documentElement.className+=' ie6';
    } else if (ie === 7) {
    document.documentElement.className+=' ie7';
    } else if (ie === 8) {
    document.documentElement.className+=' ie8';
    } else if (ie === 9) {
    document.documentElement.className+=' ie9';
    }
    10 changes: 0 additions & 10 deletions gistfile2.txt
    Original file line number Diff line number Diff line change
    @@ -1,10 +0,0 @@
    // ie10 doesn't support conditional comments but it does support @cc_on
    // @cc_on activates conditional comments within a script
    // http://msdn.microsoft.com/en-us/library/8ka90k2e%28v=vs.94%29.aspx
    <style>
    .ie10{}
    </style>

    <!--[if !IE]><!--<script>
    if (/*@cc_on!@*/false) { document.documentElement.className+=' ie10'; }
    </script><!--<![endif]-->
    7 changes: 7 additions & 0 deletions ie10-detect.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    // ie10 doesn't support conditional comments but it does support @cc_on
    // @cc_on activates conditional comments within a script
    // appends class of "ie10" to the document's html element
    // http://msdn.microsoft.com/en-us/library/8ka90k2e%28v=vs.94%29.aspx
    // demo http://dev.bowdenweb.com/ua/browsers/ie/ie10-detection-via-cc.html

    <!--[if !IE]><!--><script>if(/*@cc_on!@*/false){document.documentElement.className+=' ie10';}</script><!--<![endif]-->
  4. @jalbertbowden jalbertbowden revised this gist Mar 16, 2013. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions gistfile2.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    // ie10 doesn't support conditional comments but it does support @cc_on
    // @cc_on activates conditional comments within a script
    // http://msdn.microsoft.com/en-us/library/8ka90k2e%28v=vs.94%29.aspx
    <style>
    .ie10{}
    </style>

    <!--[if !IE]><!--<script>
    if (/*@cc_on!@*/false) { document.documentElement.className+=' ie10'; }
    </script><!--<![endif]-->
  5. @peteboere peteboere revised this gist Oct 3, 2012. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions ie-mobile-detect.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    // The same thing but for IE Mobile instead.

    var ieMobile = ( !! window.ActiveXObject && +( /IEMobile\/(\d+\.?(\d+)?)/.exec( navigator.userAgent )[1] ) ) || NaN;
  6. Pete Boere revised this gist Apr 15, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -16,4 +16,4 @@
    // ----------------------------------------------------------


    var ie = ( !!win.ActiveXObject && +( /msie\s(\d+)/i.exec( ua )[1] ) ) || NaN;
    var ie = ( !!window.ActiveXObject && +( /msie\s(\d+)/i.exec( navigator.userAgent )[1] ) ) || NaN;
  7. Pete Boere revised this gist Feb 7, 2011. 1 changed file with 7 additions and 21 deletions.
    28 changes: 7 additions & 21 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,11 @@
    // ----------------------------------------------------------
    // A short snippet for detecting versions of IE in JavaScript
    // without resorting to user-agent sniffing
    // A short snippet for detecting versions of IE:
    // Uses a combination of object detection and user-agent
    // sniffing.
    // ----------------------------------------------------------
    // If you're not in IE (or IE version is less than 5) then:
    // ie === undefined
    // If you're in IE (>=5) then you can determine which version:
    // If you're not in IE then:
    // ie === NaN // falsy
    // If you're in IE then you can determine which version:
    // ie === 7; // IE7
    // Thus, to detect IE:
    // if (ie) {}
    @@ -14,20 +15,5 @@
    // ie < 9 // Anything less than IE9
    // ----------------------------------------------------------

    // UPDATE: Now using Live NodeList idea from @jdalton

    var ie = (function(){

    var undef,
    v = 3,
    div = document.createElement('div'),
    all = div.getElementsByTagName('i');

    while (
    div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
    all[0]
    );

    return v > 4 ? v : undef;

    }());
    var ie = ( !!win.ActiveXObject && +( /msie\s(\d+)/i.exec( ua )[1] ) ) || NaN;
  8. @padolsey padolsey revised this gist Aug 21, 2010. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -18,8 +18,6 @@

    var ie = (function(){

    if (/*@cc_on!@*/true) return undef;

    var undef,
    v = 3,
    div = document.createElement('div'),
  9. @padolsey padolsey revised this gist Aug 21, 2010. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -15,14 +15,13 @@
    // ----------------------------------------------------------

    // UPDATE: Now using Live NodeList idea from @jdalton
    // and conditional compilation early exit from Scott Jehl

    var ie = (function(){

    if (/*@cc_on!@*/true) return undef;

    var undef,
    v = 4,
    v = 3,
    div = document.createElement('div'),
    all = div.getElementsByTagName('i');

    @@ -31,6 +30,6 @@ var ie = (function(){
    all[0]
    );

    return v;
    return v > 4 ? v : undef;

    }());
  10. @padolsey padolsey revised this gist Aug 20, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@
    // ie < 9 // Anything less than IE9
    // ----------------------------------------------------------

    // UPDATE: Now using Live NodeList idea from @Dalton
    // UPDATE: Now using Live NodeList idea from @jdalton
    // and conditional compilation early exit from Scott Jehl

    var ie = (function(){
  11. @padolsey padolsey revised this gist Aug 20, 2010. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    // ----------------------------------------------------------
    // A short snippet for detecting versions of IE in JavaScript
    // without resorting to user-agent sniffing
    // ----------------------------------------------------------
    // If you're not in IE (or IE version is less than 5) then:
    // ie === undefined
    // If you're in IE (>=5) then you can determine which version:
  12. @padolsey padolsey revised this gist Aug 20, 2010. 1 changed file with 13 additions and 5 deletions.
    18 changes: 13 additions & 5 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -11,15 +11,23 @@
    // ie < 9 // Anything less than IE9
    // ----------------------------------------------------------

    // UPDATE: Now using Live NodeList idea from @Dalton
    // and conditional compilation early exit from Scott Jehl

    var ie = (function(){

    var undef, v = 3, div = document.createElement('div');

    if (/*@cc_on!@*/true) return undef;

    var undef,
    v = 4,
    div = document.createElement('div'),
    all = div.getElementsByTagName('i');

    while (
    div.innerHTML = '<!--[if gt IE '+(++v)+']><i></i><![endif]-->',
    div.getElementsByTagName('i')[0]
    div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
    all[0]
    );

    return v > 4 ? v : undef;
    return v;

    }());
  13. @padolsey padolsey revised this gist Aug 17, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ----------------------------------------------------------
    // If you're not in IE (or IE version is less than 5) then:
    // ie === undefined
    // If you're in IE (>5) then you can determine which version:
    // If you're in IE (>=5) then you can determine which version:
    // ie === 7; // IE7
    // Thus, to detect IE:
    // if (ie) {}
  14. @padolsey padolsey revised this gist Aug 16, 2010. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -6,14 +6,14 @@
    // Thus, to detect IE:
    // if (ie) {}
    // And to detect the version:
    // ie && ie === 6 // IE6
    // ie && ie > 7 // IE8, IE9 ...
    // ie && ie < 9 // Anything less than IE9
    // ie === 6 // IE6
    // ie > 7 // IE8, IE9 ...
    // ie < 9 // Anything less than IE9
    // ----------------------------------------------------------

    var ie = (function(){

    var undef, v = 4, div = document.createElement('div');
    var undef, v = 3, div = document.createElement('div');

    while (
    div.innerHTML = '<!--[if gt IE '+(++v)+']><i></i><![endif]-->',
  15. @padolsey padolsey revised this gist Aug 16, 2010. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -6,9 +6,9 @@
    // Thus, to detect IE:
    // if (ie) {}
    // And to detect the version:
    // ie === 6 // IE6
    // ie > 7 // IE8, IE9 ...
    // ie < 9 // Anything less than IE9
    // ie && ie === 6 // IE6
    // ie && ie > 7 // IE8, IE9 ...
    // ie && ie < 9 // Anything less than IE9
    // ----------------------------------------------------------

    var ie = (function(){
  16. @padolsey padolsey created this gist Aug 16, 2010.
    25 changes: 25 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    // ----------------------------------------------------------
    // If you're not in IE (or IE version is less than 5) then:
    // ie === undefined
    // If you're in IE (>5) then you can determine which version:
    // ie === 7; // IE7
    // Thus, to detect IE:
    // if (ie) {}
    // And to detect the version:
    // ie === 6 // IE6
    // ie > 7 // IE8, IE9 ...
    // ie < 9 // Anything less than IE9
    // ----------------------------------------------------------

    var ie = (function(){

    var undef, v = 4, div = document.createElement('div');

    while (
    div.innerHTML = '<!--[if gt IE '+(++v)+']><i></i><![endif]-->',
    div.getElementsByTagName('i')[0]
    );

    return v > 4 ? v : undef;

    }());