browser.msie error after update to jQuery 1.9.1

前端 未结 11 1866
别那么骄傲
别那么骄傲 2020-11-27 03:32

I use the following snip of a script:

if ($.browser.msie && $.browser.version < 9) {
   extra = \"?\" + Math.floor(Math.random() * 3000);
}


        
相关标签:
11条回答
  • 2020-11-27 04:00

    $.browser was deprecated in version 1.3 and removed in 1.9

    You can verify this by viewing the documentation.

    0 讨论(0)
  • 2020-11-27 04:00

    For simple IE detection I tend to use:

    (/msie|trident/i).test(navigator.userAgent)
    

    Visit the Microsoft Developer Network to learn about the IE useragent: http://msdn.microsoft.com/library/ms537503.aspx

    0 讨论(0)
  • 2020-11-27 04:03

    The jQuery.browser options was deprecated earlier and removed in 1.9 release along with a lot of other deprecated items like .live.

    For projects and external libraries which want to upgrade to 1.9 but still want to support these features jQuery have release a migration plugin for the time being.

    If you need backward compatibility you can use migration plugin.

    0 讨论(0)
  • 2020-11-27 04:04

    I had this problem as well. We were using two versions of Jquery (1.11.3 and 1.8.3), one of which was causing this issue. I found a lightbox_me.js release that worked on both versions:

    http://buckwilson.me/lightboxme/

    It was just an easy replacement of an old file.

    0 讨论(0)
  • 2020-11-27 04:07

    Update! Complete answer overhaul for new plugin!

    The following plugin has been tested in all major browsers. It makes traditional use of userAgent string to re-equip jQuery.browser only if you're using jQuery version 1.9 or Greater!

    It has the traditional jQuery.browser.msie type properties as well as a few new ones, including a .mobile property to help decide if user is on a mobile device.

    Note: This is not a suitable replacement for feature testing. If you expect to support a specific feature on a specific device, it's still best to use traditional feature testing

    /**	jQuery.browser
     *	@author	J.D. McKinstry (2014)
     *	@description	Made to replicate older jQuery.browser command in jQuery versions 1.9+
     *	@see http://jsfiddle.net/SpYk3/wsqfbe4s/
     *
     *	@extends	jQuery
     *	@namespace	jQuery.browser
     *	@example	jQuery.browser.browser == 'browserNameInLowerCase'
     *	@example	jQuery.browser.version
     *	@example	jQuery.browser.mobile	@returns	BOOLEAN
     *	@example	jQuery.browser['browserNameInLowerCase']
     *	@example	jQuery.browser.chrome	@returns	BOOLEAN
     *	@example	jQuery.browser.safari	@returns	BOOLEAN
     *	@example	jQuery.browser.opera	@returns	BOOLEAN
     *	@example	jQuery.browser.msie	@returns	BOOLEAN
     *	@example	jQuery.browser.mozilla	@returns	BOOLEAN
     *	@example	jQuery.browser.webkit	@returns	BOOLEAN
     *	@example	jQuery.browser.ua	@returns	navigator.userAgent String
     */
    ;;(function($){var a=$.fn.jquery.split("."),b;for(b in a)a[b]=parseInt(a[b]);if(!$.browser&&(1<a[0]||9<=a[1])){a={browser:void 0,version:void 0,mobile:!1};navigator&&navigator.userAgent&&(a.ua=navigator.userAgent,a.webkit=/WebKit/i.test(a.ua),a.browserArray="MSIE Chrome Opera Kindle Silk BlackBerry PlayBook Android Safari Mozilla Nokia".split(" "),/Sony[^ ]*/i.test(a.ua)?a.mobile="Sony":/RIM Tablet/i.test(a.ua)?a.mobile="RIM Tablet":/BlackBerry/i.test(a.ua)?a.mobile="BlackBerry":/iPhone/i.test(a.ua)?
    a.mobile="iPhone":/iPad/i.test(a.ua)?a.mobile="iPad":/iPod/i.test(a.ua)?a.mobile="iPod":/Opera Mini/i.test(a.ua)?a.mobile="Opera Mini":/IEMobile/i.test(a.ua)?a.mobile="IEMobile":/BB[0-9]{1,}; Touch/i.test(a.ua)?a.mobile="BlackBerry":/Nokia/i.test(a.ua)?a.mobile="Nokia":/Android/i.test(a.ua)&&(a.mobile="Android"),/MSIE|Trident/i.test(a.ua)?(a.browser="MSIE",a.version=/MSIE/i.test(navigator.userAgent)&&0<parseFloat(a.ua.split("MSIE")[1].match(/[0-9\.]{1,}/)[0])?parseFloat(a.ua.split("MSIE")[1].match(/[0-9\.]{1,}/)[0]):
    "Edge",/Trident/i.test(a.ua)&&/rv:([0-9]{1,}[\.0-9]{0,})/.test(a.ua)&&(a.version=parseFloat(a.ua.match(/rv:([0-9]{1,}[\.0-9]{0,})/)[1].match(/[0-9\.]{1,}/)[0]))):/Chrome/.test(a.ua)?(a.browser="Chrome",a.version=parseFloat(a.ua.split("Chrome/")[1].split("Safari")[0].match(/[0-9\.]{1,}/)[0])):/Opera/.test(a.ua)?(a.browser="Opera",a.version=parseFloat(a.ua.split("Version/")[1].match(/[0-9\.]{1,}/)[0])):/Kindle|Silk|KFTT|KFOT|KFJWA|KFJWI|KFSOWI|KFTHWA|KFTHWI|KFAPWA|KFAPWI/i.test(a.ua)?(a.mobile="Kindle",
    /Silk/i.test(a.ua)?(a.browser="Silk",a.version=parseFloat(a.ua.split("Silk/")[1].split("Safari")[0].match(/[0-9\.]{1,}/)[0])):/Kindle/i.test(a.ua)&&/Version/i.test(a.ua)&&(a.browser="Kindle",a.version=parseFloat(a.ua.split("Version/")[1].split("Safari")[0].match(/[0-9\.]{1,}/)[0]))):/BlackBerry/.test(a.ua)?(a.browser="BlackBerry",a.version=parseFloat(a.ua.split("/")[1].match(/[0-9\.]{1,}/)[0])):/PlayBook/.test(a.ua)?(a.browser="PlayBook",a.version=parseFloat(a.ua.split("Version/")[1].split("Safari")[0].match(/[0-9\.]{1,}/)[0])):
    /BB[0-9]{1,}; Touch/.test(a.ua)?(a.browser="Blackberry",a.version=parseFloat(a.ua.split("Version/")[1].split("Safari")[0].match(/[0-9\.]{1,}/)[0])):/Android/.test(a.ua)?(a.browser="Android",a.version=parseFloat(a.ua.split("Version/")[1].split("Safari")[0].match(/[0-9\.]{1,}/)[0])):/Safari/.test(a.ua)?(a.browser="Safari",a.version=parseFloat(a.ua.split("Version/")[1].split("Safari")[0].match(/[0-9\.]{1,}/)[0])):/Firefox/.test(a.ua)?(a.browser="Mozilla",a.version=parseFloat(a.ua.split("Firefox/")[1].match(/[0-9\.]{1,}/)[0])):
    /Nokia/.test(a.ua)&&(a.browser="Nokia",a.version=parseFloat(a.ua.split("Browser")[1].match(/[0-9\.]{1,}/)[0])));if(a.browser)for(var c in a.browserArray)a[a.browserArray[c].toLowerCase()]=a.browser==a.browserArray[c];$.extend(!0,$.browser={},a)}})(jQuery);
    /* - - - - - - - - - - - - - - - - - - - */
    
    var b = $.browser;
    console.log($.browser);    //    see console, working example of jQuery Plugin
    console.log($.browser.chrome);
    
    for (var x in b) {
        if (x != 'init')
            $('<tr />').append(
                $('<th />', { text: x }),
                $('<td />', { text: b[x] })
            ).appendTo($('table'));
    }
    table { border-collapse: collapse; }
    th, td { border: 1px solid; padding: .25em .5em; vertical-align: top; }
    th { text-align: right; }
    
    textarea { height: 500px; width: 100%; }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <table></table>

    0 讨论(0)
提交回复
热议问题