best cricut
Jun
30
2009

jQuery IE detection issue workaround

We recently discovered an issue with jQuery.browser.version detection, it reports wrong Internet Explorer versions on some corrupted IE userAgent strings. A corrupted IE8 userAgent string may look like,

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; GTB6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET CLR 1.1.4322; InfoPath.2)

In this case jQuery.browser.version will report browser version 6.0 instead of 8.0, this will result some jQuery plugins to show a 'not implemented' error in IE8. So far we know jqModal and FancyBox are affected. Because they rely on jQuery.browser.version to detect IE6, and run some IE6 specific codes, which caused IE8 to fail, another sad story from MS.

Although we believe it's not the problem with jQuery or IE (Microsoft) alone, the best fix will be patching the plugins to detect IE6. i.e. to detect IE6 properly with jQuery, you will need the following code, which has an extra check by using window.XMLHttpRequest.

ie6=$.browser.msie&&($.browser.version == "6.0")&&!window.XMLHttpRequest;

If you curious about how userAgnet string got corrupted, we don't have much clue about it, some say it's due to an earlier release of IE8 (however as we aware, some IE7 has got the same issue), but in our office 3 out of 10 PCs has got the corrupted string. To fix it, you need to look for the following registry keys,

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent\Post Platform
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\User Agent\Post Platform
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent\Post Platform
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\User Agent\Post Platform

Or if you want to do more then just differentiate IEs, you may find a good browser detection Javascript here.

Some side note, you might notice jQuery has marked jQuery.browser deprecated since 1.3 in the favour of jQuery.support. We understand why jQuery would want to take this approach, and it's a good step forward. However jQuery.support would only be good if it tells all the feature differences among browsers, rendering engines, and standard modes. As web develops we don't learn the differences first then start developing a site, we only come across the differences and try to figure out what feature difference cause the different final result will be really time consuming. Until the time all the browsers come to the same standard and feature set, patching and hacking may be the only way for web developers, no one-stop solution would be available at any moment before that epoch. May God blessing all the web developers please.

Be Sociable, Share!

9 Comments

  • Thank you so much!! Very well explained. Fixed our problem too!

  • kost says:

    Thank you!

    Fixed my problems with wrong IE8/IE6 detection.

  • Garry says:

    Great post and thank you for doing it. Has saved me a massive headache!

  • thorn says:

    Thank you for sharing this.
    Was this issue submitted to the jQuery bug tracker?

  • Greg says:

    I’m having this issue using jq.modal. Where would I put this code?

    ie6=$.browser.msie&&($.browser.version == “6.0”)&&!window.XMLHttpRequest;

  • Jose Manuel says:

    My solution:

    The code for jqmodal:

    var BrowserDetect = {
    init: function () {
    this.browser = this.searchString(this.dataBrowser) || “An unknown browser”;
    this.version = this.searchVersion(navigator.userAgent)
    || this.searchVersion(navigator.appVersion)
    || “an unknown version”;
    this.OS = this.searchString(this.dataOS) || “an unknown OS”;
    },
    searchString: function (data) {
    for (var i=0;i<data.length;i++) {
    var dataString = data[i].string;
    var dataProp = data[i].prop;
    this.versionSearchString = data[i].versionSearch || data[i].identity;
    if (dataString) {
    if (dataString.indexOf(data[i].subString) != -1)
    return data[i].identity;
    }
    else if (dataProp)
    return data[i].identity;
    }
    },
    searchVersion: function (dataString) {
    var index = dataString.indexOf(this.versionSearchString);
    if (index == -1) return;
    return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
    },
    dataBrowser: [
    {
    string: navigator.userAgent,
    subString: "Chrome",
    identity: "Chrome"
    },
    { string: navigator.userAgent,
    subString: "OmniWeb",
    versionSearch: "OmniWeb/",
    identity: "OmniWeb"
    },
    {
    string: navigator.vendor,
    subString: "Apple",
    identity: "Safari",
    versionSearch: "Version"
    },
    {
    prop: window.opera,
    identity: "Opera"
    },
    {
    string: navigator.vendor,
    subString: "iCab",
    identity: "iCab"
    },
    {
    string: navigator.vendor,
    subString: "KDE",
    identity: "Konqueror"
    },
    {
    string: navigator.userAgent,
    subString: "Firefox",
    identity: "Firefox"
    },
    {
    string: navigator.vendor,
    subString: "Camino",
    identity: "Camino"
    },
    { // for newer Netscapes (6+)
    string: navigator.userAgent,
    subString: "Netscape",
    identity: "Netscape"
    },
    {
    string: navigator.userAgent,
    subString: "MSIE",
    identity: "Explorer",
    versionSearch: "MSIE"
    },
    {
    string: navigator.userAgent,
    subString: "Gecko",
    identity: "Mozilla",
    versionSearch: "rv"
    },
    { // for older Netscapes (4-)
    string: navigator.userAgent,
    subString: "Mozilla",
    identity: "Netscape",
    versionSearch: "Mozilla"
    }
    ],
    dataOS : [
    {
    string: navigator.platform,
    subString: "Win",
    identity: "Windows"
    },
    {
    string: navigator.platform,
    subString: "Mac",
    identity: "Mac"
    },
    {
    string: navigator.userAgent,
    subString: "iPhone",
    identity: "iPhone/iPod"
    },
    {
    string: navigator.platform,
    subString: "Linux",
    identity: "Linux"
    }
    ]

    };
    BrowserDetect.init();

    /*
    * jqModal – Minimalist Modaling with jQuery
    * (http://dev.iceburg.net/jquery/jqModal/)
    *
    * Copyright (c) 2007,2008 Brice Burgess
    * Dual licensed under the MIT and GPL licenses:
    * http://www.opensource.org/licenses/mit-license.php
    * http://www.gnu.org/licenses/gpl.html
    *
    * $Version: 03/01/2009 +r14
    */
    (function($) {
    $.fn.jqm=function(o){
    var p={
    overlay: 50,
    overlayClass: ‘jqmOverlay’,
    closeClass: ‘jqmClose’,
    trigger: ‘.jqModal’,
    ajax: F,
    ajaxText: ”,
    target: F,
    modal: F,
    toTop: F,
    onShow: F,
    onHide: F,
    onLoad: F
    };
    return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;
    H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass(‘jqmID’+s),s:s};
    if(p.trigger)$(this).jqmAddTrigger(p.trigger);
    });};

    $.fn.jqmAddClose=function(e){return hs(this,e,’jqmHide’);};
    $.fn.jqmAddTrigger=function(e){return hs(this,e,’jqmShow’);};
    $.fn.jqmShow=function(t){return this.each(function(){t=t||window.event;$.jqm.open(this._jqm,t);});};
    $.fn.jqmHide=function(t){return this.each(function(){t=t||window.event;$.jqm.close(this._jqm,t)});};

    $.jqm = {
    hash:{},
    open:function(s,t){var h=H[s],c=h.c,cc=’.’+c.closeClass,z=(parseInt(h.w.css(‘z-index’))),z=(z>0)?z:3000,o=$(”).css({height:’100%’,width:’100%’,position:’fixed’,left:0,top:0,’z-index’:z-1,opacity:c.overlay/100});if(h.a)return F;h.t=t;h.a=true;h.w.css(‘z-index’,z);
    if(c.modal) {if(!A[0])L(‘bind’);A.push(s);}
    else if(c.overlay > 0)h.w.jqmAddClose(o);
    else o=F;

    h.o=(o)?o.addClass(c.overlayClass).prependTo(‘body’):F;
    if(ie6){$(‘html,body’).css({height:’100%’,width:’100%’});if(o){o=o.css({position:’absolute’})[0];for(var y in {Top:1,Left:1})o.style.setExpression(y.toLowerCase(),”(_=(document.documentElement.scroll”+y+” || document.body.scroll”+y+”))+’px'”);}}

    if(c.ajax) {var r=c.target||h.w,u=c.ajax,r=(typeof r == ‘string’)?$(r,h.w):$(r),u=(u.substr(0,1) == ‘@’)?$(t).attr(u.substring(1)):u;
    r.html(c.ajaxText).load(u,function(){if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h);});}
    else if(cc)h.w.jqmAddClose($(cc,h.w));

    if(c.toTop&&h.o)h.w.before(”).insertAfter(h.o);
    (c.onShow)?c.onShow(h):h.w.show();e(h);return F;
    },
    close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
    if(A[0]){A.pop();if(!A[0])L(‘unbind’);}
    if(h.c.toTop&&h.o)$(‘#jqmP’+h.w[0]._jqm).after(h.w).remove();
    if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
    },
    params:{}};
    var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version == “6.0”)&&(BrowserDetect.version!=8),F=false,
    i=$(”).css({opacity:0}),
    e=function(h){if(ie6)if(h.o)h.o.html(”).prepend(i);else if(!$(‘iframe.jqm’,h.w)[0])h.w.prepend(i); f(h);},
    f=function(h){try{$(‘:input:visible’,h.w)[0].focus();}catch(_){}},
    L=function(t){$()[t](“keypress”,m)[t](“keydown”,m)[t](“mousedown”,m);},
    m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents(‘.jqmID’+h.s)[0]);if(r)f(h);return !r;},
    hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
    if(!this[c]){this[c]=[];$(this).click(function(){for(var i in {jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return F;});}this[c].push(s);});});};
    })(jQuery);

  • Oleg says:

    Simply and fats, thanks!

RSS feed for comments on this post.


Copyright Orite Group Pty Ltd | Powered by WordPress | Theme: Aeros 2.0

https://www.runthemusic.com/