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

JavascriptJqueryJquery Tools

Javascript Problem Overview


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?

Javascript Solutions


Solution 1 - Javascript

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:

Solution 2 - Javascript

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.

Solution 3 - Javascript

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.

Solution 4 - Javascript

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>

Solution 5 - Javascript

I've simply added

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

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

Solution 6 - Javascript

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.

Solution 7 - Javascript

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.)

Solution 8 - Javascript

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

Solution 9 - Javascript

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;
        }
    });
});

Solution 10 - Javascript

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

Solution 11 - Javascript

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

Solution 12 - Javascript

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

Solution 13 - Javascript

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionColin747View Question on Stackoverflow
Solution 1 - JavascriptJrBrionesView Answer on Stackoverflow
Solution 2 - JavascriptAlexanderView Answer on Stackoverflow
Solution 3 - JavascriptManisha SrivastavaView Answer on Stackoverflow
Solution 4 - JavascriptAtik KhanView Answer on Stackoverflow
Solution 5 - JavascriptuserlondView Answer on Stackoverflow
Solution 6 - JavascriptPointyView Answer on Stackoverflow
Solution 7 - JavascriptLerin SonbergView Answer on Stackoverflow
Solution 8 - JavascriptBugfixerView Answer on Stackoverflow
Solution 9 - JavascriptAishwarya KumarView Answer on Stackoverflow
Solution 10 - JavascriptHamidSadeghiView Answer on Stackoverflow
Solution 11 - JavascriptArezooView Answer on Stackoverflow
Solution 12 - JavascriptLogicFirstView Answer on Stackoverflow
Solution 13 - JavascriptCarlos UCRView Answer on Stackoverflow