user1920546
user1920546

Reputation: 1

Trim of string doesn't display in IE prior to 9

   {{if inventory.title.length > 38}}
            <p class="p1">
                {{>(inventory.title.substring(0, 38) + '...').trim()}}
            </p>

How do I correct this code to display in IE previous to IE9. I continue to get the following

Error: Object doesn't support property or method 'trim'.

Upvotes: 0

Views: 110

Answers (1)

closure
closure

Reputation: 7452

Trim was not part of String till ECMAScript 5. IE9 is the first browser to support ECMAScript 5.

Though not recommended to modify the prototype of base classes,
if you wish you can add following lines of code for String.trim to work in all browsers.

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

Upvotes: 1

Related Questions