0

I am trying to upgrade an old piece of code that is not working in jquery 1.10 since browser check has been removed. I don't want to use migration plugin.

How best can i do the following 2 lines?

var pos = ($.browser.msie && parseInt($.browser.version) <= 8) ? 'absolute' : 'fixed';

if ($.browser.msie && parseInt($.browser.version) <= 6) 
top = top + $(window).scrollTop();

I am trying to get direction from my director to stop supporting IE 7 and less but till then i need to find a way to make the second piece of code working normal again.

learning...
  • 3,104
  • 10
  • 58
  • 96
  • 2
    _"I don't want to use migration plugin."_ Why not? – j08691 Nov 22 '13 at 20:39
  • 1
    Basically, you would need to find a way to write your code that wouldn't need to rely on browser sniffing. – Kevin B Nov 22 '13 at 20:41
  • 1
    offtopic , jqUery has done a huge mistake with all this "migration/stopped supporting" stuff. im stuck with 1.9 and i don't think i will ever update.... – Royi Namir Nov 22 '13 at 20:42
  • Please take a look at the answer below that i have brought in from another post... – learning... Nov 22 '13 at 20:45
  • 2
    @RoyiNamir If you can use 1.9, you should be able to use 1.10 and 1.11 without any issues. – Kevin B Nov 22 '13 at 20:47
  • Browser sniffing has been superseeded IMO with tools such as Modernizr. We shouldn't be checking what browser it is rather what the browser can do. – mbx-mbx Nov 22 '13 at 20:47
  • @Magrangs with all the respect - i wont add a library just to check for a single feature detection. – Royi Namir Nov 22 '13 at 20:48
  • 1
    @RoyiNamir It may be one feature now, could end up being a hell of a lot more in the future. It is lightweight and fast so there are no real issues in using it. – mbx-mbx Nov 22 '13 at 20:49
  • @KevinB yes i meant the suppressed IE support. – Royi Namir Nov 22 '13 at 20:49
  • Right, but why is that a mistake? you can continue using the 1.x branch of jquery to get full IE support. you aren't losing anything functionality-wise by using 1.x rather than 2.x, rather, you're gaining a faster version of jquery that you can include for all modern browsers. – Kevin B Nov 22 '13 at 20:50
  • @RoyiNamir p.s. they removed it for a reason... – mbx-mbx Nov 22 '13 at 20:52
  • @KevinB people still use ie8. and i feel that as a web developer i should provide support for ie8 also. and now , I can not automatically update to last version as i used to do. – Royi Namir Nov 22 '13 at 20:53
  • the automatic update idea is terrible anyway, it gets served with cache headers that don't last long enough, and results in broken code if anything major changes. – Kevin B Nov 22 '13 at 20:57
  • @Magrangs "It may be one feature now..." This is the reason i am trying to remove the old plugins or upgrade if newer version is available, including site specific code as well. I can do this upgrade at this time since i am upgrading the site to VS 2013 and Mvc 5. I want the site to be jquery 1.10 compliant. – learning... Nov 22 '13 at 20:57

1 Answers1

0

I have found this by @John in another post, is this a viable solution?

Author: @John in this post

// ----------------------------------------------------------
// 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:
//     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
// ----------------------------------------------------------

// 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;

}());
Community
  • 1
  • 1
learning...
  • 3,104
  • 10
  • 58
  • 96