osahyoun / instagram-search

Simple Web App for searching Instagram
60 stars 29 forks source link

Object doesn't support this property or method. IE8 and older #2

Closed ellefsen closed 12 years ago

ellefsen commented 12 years ago

By the way, great stuff. Exactly what I needed for a super simple Instagram competition we are creating. I'm getting an error in IE8 and older saying "Object doesn't support this property or method." I'm a real js rookie, so I have no idea how to debug it and find a proper solution. Any help would be appreciated.

function generateResource(tag){
    var config = Instagram.Config, url;

    if(typeof tag === 'undefined'){
      throw new Error("Resource requires a tag. Try searching for cats!");
    } else {
      // Make sure tag is a string, trim any trailing/leading whitespace and take only the first 
      // word, if there are multiple.
      tag = String(tag).trim().split(" ")[0];
    }

    url = config.apiHost + "/v1/tags/" + tag + "/media/recent?callback=?&client_id=" + config.clientID;

    return function(max_id){
      var next_page;
      if(typeof max_id === 'string' && max_id.trim() !== '') {
        next_page = url + "&max_id=" + max_id;
      }
      return next_page || url;
    };
  }

This is the line that produces the error

tag = String(tag).trim().split(" ")[0];
osahyoun commented 12 years ago

Thanks for raising this. The problem is that the string method trim is not supported by IE8 and below. You'd need to implement your own version:

// Add trim function support
if(typeof String.prototype.trim !== 'function') {
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g, ''); 
    }
}

There's no reason why this shouldn't be in the script... I'll commit it as soon as I have a moment.

ellefsen commented 12 years ago

That seems to have solved it, thanks. And a huge thanks for the quick reply!