views:

729

answers:

4

I cannot seem to figure out I am getting the following error in IE 8 (only IE version I've tested so far). The script runs fine in all (chrome, ff, safari) other browsers I've tested. What am I doing wrong?

Error:

Message: Object doesn't support this property or method Line: 52 Char: 29 Code: 0 URI: http://www.ntierdesign.com/jquery/livetwitter/Scripts/jquery.liveTwitter.js

Message: Object doesn't support this property or method Line: 1 Char: 1 Code: 0 URI: http://twitter.com/status/user%5Ftimeline/bloomsdayreg.json?count=3&callback=jsonp1251868075768&%5F=1251868075882

Example:

Hopefully I won't cap out my twitter api rate limit too fast, but you can view an example of the page here http://ntierdesign.com/jquery/livetwitter/

+1  A: 

You are having this error because the version of IE that you are using doesn't implements Array/indexOf, which has been introduced in JavaScript 1.6.

However you could add the indexOf method to the Array prototype if it doesn't exists, for compatibility.

This is the implementation that Firefox uses internally:

if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function(elt /*, from*/) {
    var len = this.length >>> 0;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++) {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

Check with IE this example of your page, having the compatibility function added, runs without problems...

CMS
Thanks CMS, I haven't done a lot of javascript dev, but I'm really surprised that I've never run into that before.
NATO24
You're welcome @ntierdesign... welcome to the strange world of cross-browser scripting... :-)
CMS
A: 

The error points directly to line 52, char 29, which is the .indexOf method on array.

this method is not implemented on IE's javascript - hence the error.

luckily there are tons of workarounds on the web, eg. link text

Ken Egozi
Thanks Ken, that was the it.
NATO24
A: 

Just noticed that if you want to use a native jQuery approach, you can use the inArray function in the utilities class. jQuery inArray Documentation

NATO24
A: 

You might want to reconsider the name, I've already released a similar plugin. :)

http://github.com/elektronaut/jquery.livetwitter/tree/master

elektronaut
Nice work elektronaut. No worries, it's not really for public consumption. I only made it a plugin, so I could learn more.
NATO24