jQuery url.indexOf is not a function

Viewed 9066

I have just installed jQuery using

npm install jquery

After merging jquery,bootstrap in a vendor file using Webpack , I am keep on getting following error

vendor.4b59d15129c2efa4408c.js:9979 Uncaught TypeError: url.indexOf is not a function
    at jQuery.fn.init.jQuery.fn.load (vendor.4b59d15129c2efa4408c.js:9979)
    at Object.<anonymous> (bundle.7beebbf8c43d73f31563.js:55)
    at Object.<anonymous> (bundle.7beebbf8c43d73f31563.js:213)
    at __webpack_require__ (vendor.4b59d15129c2efa4408c.js:55)
    at Object.<anonymous> (bundle.7beebbf8c43d73f31563.js:12)
    at __webpack_require__ (vendor.4b59d15129c2efa4408c.js:55)
    at webpackJsonpCallback (vendor.4b59d15129c2efa4408c.js:26)
    at bundle.7beebbf8c43d73f31563.js:1
3 Answers

What is your jQuery version? On version 3, the function $(window).load() is deprecated. When using .load(), .unload(), or .error() it will throw an error.

Replace those function with:

old

$(window).load( function () {} )

version 3 above

$(window).on('load', function () {} )

$(window).on('error', function () {} )

my own case was using SuperSimpleSlider jQuery plugins with Vue.js. I have to replace the original file (the plugins) with correct solution.

Hope this helps!

Source: jqueryhouse.com

I suppose that url is a string, so i deduce that is a problem when you set url, try to find that line and replace with console.log(url) to see if it is defined.

Change this in your code:

off = url.indexOf( " " );

to:

off = url ? url.indexOf( " " ) : -1;

In short, you are trying to access indexOf on null or undefined, which throws that error. So what I do is check if url exists, then access indexOf, otherwise set to -1 which is what indexOf would return if url doesn't contain the empty string.

Related