Internet Explorer 6: No String.trim() support

0 Comments

Its not exactly a well kept secret that web developers loathe IE6, but I never expected to leave out a simple function such as String.trim().

A simple test script such as this would cause an error.

1.alert("     hello world    ".trim());

image
An unwelcome surprise.

Luckily, theres an easy fix for that! Simply paste this code near the top before any trim() calls are made.

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

image 
Yay its working now!

[ Source ]

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog