Reputation: 1
I face One problem in JavaScript .What it is now I am using dojo componets in jsp page. So I changed trim function into WhiteSpaceTrimmer function. But it is working in mozilla Firefox not in IE8.in i.e. shows one error:var ItemLot=(temp2[1].trim()+"*"+temp2[5].trim());
not a method.
Here if we remove trim function it is working but my final step takes only trim value.
Upvotes: 0
Views: 556
Reputation: 4543
Dojo provides methods dojo.trim()
and dojo.string.trim()
which will use the native String.prototype.trim() method if available, and provide an implementation in JS if not, much like what @jfriend00 suggests. If you're using Dojo and you need to support older browsers, you might as well use these. Pass in the string as the only argument.
Upvotes: 0
Reputation: 707158
Older versions of IE do not support the String.trim
method. You can add this code to your startup code for your page to add the trim method to the String object in case it doesn't exist:
if(!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g,'');
};
}
Source: MDN.
Upvotes: 1