Internet Explorer 6: No String.trim() support

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.

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

An unwelcome surprise.

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

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

Yay its working now!

[ Source ]

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