javascript - jQuery IE9-10: unable to get property replace of undefined or null reference - Stack Overflow

I'm developing a page with the following libraries;jQuery (1.7.2) (older version because of a depe

I'm developing a page with the following libraries;

  • jQuery (1.7.2) (older version because of a dependency issue, but have tried up to 1.9.1, doesn't fix issue).
  • Backbone (1.1.0)
  • lodash (2.4.1)
  • modernizr (2.7.1)
  • gsap (1.17.0)

The page use canvas and gsap for animation. Everything works great in IE11, Chrome, Safari, Firefox, and IE8 (animations disabled for IE8), but IE9 and 10 just throw this error in the console over and

unable to get property 'replace' of undefined or null reference

The line referenced is in jquery.js, line 622, which is the return statement in this code:

// Convert dashed to camelCase; used by the css and data modules
// Microsoft forgot to hump their vendor prefix (#9572)
camelCase: function( string ) {
    return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
},

I can't figure out how to determine what part of MY code caused this jQuery code to fire, so I'm unsure as to what may be the issue on my end.

Does anyone know a fix for this? Or alternatively, how I can view what part of my code caused this jquery code to fire (using IE dev tools)?

I'm developing a page with the following libraries;

  • jQuery (1.7.2) (older version because of a dependency issue, but have tried up to 1.9.1, doesn't fix issue).
  • Backbone (1.1.0)
  • lodash (2.4.1)
  • modernizr (2.7.1)
  • gsap (1.17.0)

The page use canvas and gsap for animation. Everything works great in IE11, Chrome, Safari, Firefox, and IE8 (animations disabled for IE8), but IE9 and 10 just throw this error in the console over and

unable to get property 'replace' of undefined or null reference

The line referenced is in jquery.js, line 622, which is the return statement in this code:

// Convert dashed to camelCase; used by the css and data modules
// Microsoft forgot to hump their vendor prefix (#9572)
camelCase: function( string ) {
    return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
},

I can't figure out how to determine what part of MY code caused this jQuery code to fire, so I'm unsure as to what may be the issue on my end.

Does anyone know a fix for this? Or alternatively, how I can view what part of my code caused this jquery code to fire (using IE dev tools)?

Share Improve this question asked Aug 28, 2015 at 20:54 tdctdc 5,46412 gold badges59 silver badges107 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 1

Turns out the issue wasn't something inherently wrong with IE, but rather I was trying to access an object which didn't entirely exist yet. The other browsers this was not an issue (perhaps their JS engines were just fast enough for it to be a non-issue), but I've now added checks to ensure all the relevant content has loaded before executing the problematic function and the issue seems to be gone. Thanks for the help, all.

What kind of tool are you using for debugging? I have a solution for you for Chrome debug console
1. First go Find the jquery script file in the console, right click and select "Blackbox script" it is going to be ignored while debugging, only your files are going to be considered
2. Activate break on errors and a breakpoint is going to be triggered on the line of code where the exception is occurring
Check JavaScript: Is there a way to get Chrome to break on all errors?
and https://developer.chrome./devtools/docs/blackboxing

Maybe I'm wrong here but is it possible that IE8-9 "string" is a reserved word? Maybe not. But the only time .replace would show that message is if you were not feeding it a string.

camelCase: function( string ) {
    if(!string){ 
         console.log("string is falsy", string);
         return string;
    }
    return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
},

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745341741a4623357.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信