Uncaught TypeError: Cannot read property 'msie' of undefined - jQuery tools
Asked Answered
A

13

205

I am getting the following error in Chrome dev console:

Uncaught TypeError: Cannot read property 'msie' of undefined

My understanding is that it is because .browser is now deprecated in jQuery however I am using the latest version of jQuery tools and it is still giving the error, I checked in the js file and it is there.

How can I get around this so it does not give the error?

Adulthood answered 17/2, 2013 at 16:31 Comment(11)
this error is insufficient. From what element are you trying to read this from?Tammietammuz
I haven't used .browser in my code at all. It seems to be detecting it in the jQuery tools file.Adulthood
The browser object is not only deprecated in 1.9, it's gone. If jQuery Tools is still using it, then jQuery Tools is broken.Disconsolate
It doesn't matter if you are using $.browser or not. If any of your dependencies is using then you need itSubmarine
@Colin747, having said that, can you try using the jQuery Migrate Plugin as described in the jQuery download page?Submarine
@Submarine that seemed to get rid of the error. You can put an answer up if you like.Adulthood
@Colin747, I believe you can set jQuery.migrateMute and jQuery.migrateTrace to falseSubmarine
@Submarine I found a CDN that doesn't produce logging but thanks, if you want to put an answer up I'll acceptAdulthood
@Colin747, ok, i will post itSubmarine
The latest jQuery Tools has only been tested with jQuery 1.7. jQuery 1.9 is not compatible with the latest version of jQuery Tools; it's that simple. Dump jQuery Tools or downgrade jQuery to any version below 1.9 that works. Otherwise, don't expect anyone to update jQuery Tools, it's been without a developer for the last few years.Sligo
is this error related to using admin with overlay mode?Silvasilvain
S
199

The $.browser method has been removed as of jQuery 1.9.

jQuery.browser() removed

The jQuery.browser() method has been deprecated since jQuery 1.3 and is removed in 1.9. If needed, it is available as part of the jQuery Migrate plugin. We recommend using feature detection with a library such as Modernizr.

jQuery Core 1.9 Upgrade Guide.

As stated in the Upgrade Guide you can try using the jQuery Migrate plugin to restore this functionality and let jQuery Tools work.

Submarine answered 17/2, 2013 at 16:50 Comment(0)
F
285

You can check out this solution by AJ. It's pretty straightforward, just copy and paste the following lines of code.

jQuery.browser = {};
(function () {
    jQuery.browser.msie = false;
    jQuery.browser.version = 0;
    if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
        jQuery.browser.msie = true;
        jQuery.browser.version = RegExp.$1;
    }
})();

Reference:

Fabri answered 6/6, 2013 at 21:59 Comment(3)
This works Perfect! But I take it this should be used as a patch, rather than a solution right?Frazzled
This answer is no longer correct, since IE11 does not have the MSIE token in the userAgent string.Homily
I put this code but it is not working for Chrome browser!Malachi
S
199

The $.browser method has been removed as of jQuery 1.9.

jQuery.browser() removed

The jQuery.browser() method has been deprecated since jQuery 1.3 and is removed in 1.9. If needed, it is available as part of the jQuery Migrate plugin. We recommend using feature detection with a library such as Modernizr.

jQuery Core 1.9 Upgrade Guide.

As stated in the Upgrade Guide you can try using the jQuery Migrate plugin to restore this functionality and let jQuery Tools work.

Submarine answered 17/2, 2013 at 16:50 Comment(0)
G
54

Use the following script tag in your jsp/js file:

<script src="http://code.jquery.com/jquery-1.9.0.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>

this will work for sure.

Gigantopithecus answered 3/7, 2014 at 12:42 Comment(4)
make sure you have working internet connection. If you are using offline then download the js file at your end, and then refer that file.Gigantopithecus
Well I can see that it is hosted online... anyways thanks I resolved it with jquery.noConflict() as I had two versions to jquery being used on the same page.Clavicytherium
@User5590 : anytime :)Gigantopithecus
Shouldn't use non minified jquery in production : check cdnjs.com for example. And use HTTPS instead.Galvanic
S
35

I use below code after js file include and it's working now.

<script src="js/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
    jQuery.browser = {};
    (function () {
        jQuery.browser.msie = false;
        jQuery.browser.version = 0;
        if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
            jQuery.browser.msie = true;
            jQuery.browser.version = RegExp.$1;
        }
    })();
</script>
Smolder answered 30/8, 2016 at 11:6 Comment(1)
This link link gives me error, but this little piece of code you wrote helped me a lot, thanks man.Fourpence
C
11

I've simply added

jQuery.browser = {
    msie: false,
    version: 0
};

after jquery script, because I don't care about IE anymore.

Caryopsis answered 28/6, 2019 at 5:42 Comment(1)
Thank bro. I got those type of error and solved my issue which is provided by your solution.Marchand
D
7

Here is the jQuery Tools bug on GitHub. You can try one of the patches.

edit — it doesn't look to me as if jQuery Tools is getting much support. I personally would not begin a new project with a dependency on that library unless I were prepared to take over support myself.

Disconsolate answered 17/2, 2013 at 16:36 Comment(3)
+1, jQuery Tools has been a complete mess for the last few years. That it's not "getting much support" is very accurate and a huge understatement. I think there's only been one minor update since jQuery 1.3 and no developer for the last couple of years as well.Sligo
Agreed, does anyone have a recommendation for a replacement library? Something with a scroller, overlay and range input slider? I avoid jQuery mobile because it comes pre-styled. I have styled it before and it's a nightmare.Bernadine
I've moved to just finding well written minimal libraries for each function I want. ie: range input slider: loopj.com/jquery-simple-slider, scroller/slider: bxslider.com. I find much better support and and overall smaller footprint finding individual libraries like theseTartaglia
H
3

As I don't plan to support old MS IE versions at all, I've simply replaced all references to browser.msie with false. Not a nice solution, I know, but it works for me.

(Actually, they appeared as !browser.msie, which could be omitted from the conditions.)

Henriettahenriette answered 2/9, 2013 at 20:28 Comment(0)
J
3

Replace Your JS with

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

Source link

Joyajoyan answered 26/8, 2015 at 11:23 Comment(1)
At the moment for jquery 1.7+ the latest jquery-ui is: <link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>Northwesterly
A
2

See this issue mainly rises due to browser navigation and version properties. For this you have to add just following code in function :

/* solution to undefined msie */
jQuery.browser = {};
jQuery.browser.msie = false;
    jQuery.browser.version = 0;
    if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
        jQuery.browser.msie = true;
        jQuery.browser.version = RegExp.$1;
    }
/* solution to undefined msie */    

For exapmle I am using it on click function, see it:

 $(document).on('click', '.remove_add_test', function() {
    var product_id = $(this).data('id');
    var thisproduct = $(this);
    
    /* solution to undefined msie */
    jQuery.browser = {};
    jQuery.browser.msie = false;
        jQuery.browser.version = 0;
        if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
            jQuery.browser.msie = true;
            jQuery.browser.version = RegExp.$1;
        }
    /* solution to undefined msie */    
    
    jConfirm('Are you sure you want to delete record?', 'Remove Product', function(r) {
        if (r == true) {
            $.ajax({
                type: 'POST',
                url: 'scripts/ajax/index.php',
                data: {
                    method: 'removeproduct_fromcart',
                    id: product_id
                },
                dataType: 'json',
                success: function(data) {
                    if (data.RESULT == 0) {
                        $(".price span").text(data.totalprice);
                        $(thisproduct).closest('tr').remove();
                        $(".cart-number").text(data.productcount - 1);
                        $.growl.notice({
                            title: "Shopping Cart",
                            message: data.MSG
                        });
                       location.reload();
                        // window.location.href = 'https://www.youth-revisited.co.uk/payment.html';

                    }
                    // window.location.href = 'https://www.youth-revisited.co.uk/payment.html';
                }
            });
            // window.location.href = 'https://www.youth-revisited.co.uk/payment.html';

        } else {
            return false;
        }
    });
});
Archdeacon answered 25/3, 2021 at 4:52 Comment(0)
A
0

Use like blow

$(function (a) {

. . . . .then in your function you can using msie property like

if (a.browser.msie) 
{
}
else 
{
   $(settings.current).after(Uploadelement);
}

goodluck

Arlettaarlette answered 5/9, 2013 at 12:12 Comment(0)
C
0

Use like blow

i use this command and solve

"Uncaught TypeError: Cannot read property 'msie' of undefined" Error

if (/1\.(0|1|2)\.(0|1|2)/.test($.fn.jquery) || /^1.1/.test($.fn.jquery)) {
    return;
}
Colunga answered 9/6, 2015 at 12:21 Comment(0)
U
0

I was getting this error while using JQuery 1.10 and JQuery UI 1.8. I was able to resolve this error by updating to the latest JQuery UI 1.11.4.

Steps to update JQuery UI from Visual Studio:

  • Navigate to Project or Solution
  • Right click: "Manage NuGet Packages"
  • On the left, click on "Installed Packages" tab
  • Look for "JQuery UI (Combined library)" and click Update
  • If found, Select it and click Update
  • If not found, find it in "Online > nuget.org" tab on the left and click install. If the old version of Jquery UI version is still existing, it can be deleted from the project
Upthrow answered 21/12, 2015 at 14:42 Comment(0)
G
0

If you have jQuery defined twice, then you could get this error. For example, if you are working with Primefaces (it already includes jQuery) and you define it in other place.

Grub answered 4/12, 2018 at 2:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.