IE Javascript error “Object doesn't support this property or method” within jQuery

 ̄綄美尐妖づ 提交于 2019-12-19 17:36:18

问题


For some reason, I am getting the following Javascript error in Internet Explorer 8 on line 3156 of jquery.js (version 1.4.3, non-compressed version): Object doesn't support this property or method. No error occurs in Firefox and Google Chrome.

This is the line the error occurs on:

if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {

Investigation (console.log(Expr.leftMatch[type])) produces the following interesting result: In Google Chrome, it outputs

/(^(?:.|\r|\n)*?):((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\3\))?(?![^\[]*\])(?![^\(]*\))/

However in Internet Explorer this is the output:

function() {
  var p = this;
  do p = p.previousSibling;
  while (p && p.nodeType != 1);
  return p;
}

On which exec cannot be called (it is undefined). The quoted function is not present within jquery.js. Does anyone have any clue why this happens, or what I can do to solve it?

I have, unfortunately, not yet been able to create a simple script to reproduce the problem, although I did find this post of someone having the same problem, but it does not offer a solution (the last post suggests the page should be run in Standards Mode, but mine already is).


回答1:


As it turns out, I managed to figure it out by myself after several painful hours. It appears the Sizzle selector engine breaks in this unexpected way (and only in Internet Explorer), if you have defined Object.prototype.previousObject elsewhere.

Removing that declaration, or renaming previousObject to something else fixes the problem.

The funny thing is, I even put that code there myself (the Object.prototype.previousObject = [the function in my question]), but I did not recognize the code.

Well, that's another day full of development potential wasted.




回答2:


I have discovered the same behaviour occurs if you attempt to add a method called "inherited" to the Object.prototype, ie Object.prototype.inherited = <some func>

It affects IE6, 7 & 8 but seems to be fixed in IE9 (beta)



来源:https://stackoverflow.com/questions/3968416/ie-javascript-error-object-doesnt-support-this-property-or-method-within-jque

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!