I came across a problem in Internet Explorer (it wasn’t a problem with Firefox) when I was trying to compare two strings. To me, one string looked to have an extra space in the front. No problem, I’ll just call the jQuery trim function. Well, that didn’t work. So I used charCodeAt and found it was ASCII character 160. I looked up char code 160 and saw that it is a “Non-breaking space”. You would think that a “space” character would be trimmed. I looked at the jQuery code that does the trimming and the grep pattern uses
\s. So, evidently you can’t use
\s to catch the “Non-breaking space” in IE. I wonder why no one else has seen this. I wrote up a test page to illustrate this.
To create the non-breaking space, you can use
String.fromCharCode(160) or the Unicode representation “\u00A0”. “ ” doesn’t seem to work when using regular expressions, although it behaves the same when printed.
|Browser||Evaluates character 160 as white-space|
|Firefox 3, 3.5||Yes|
|Internet Explorer 7, 8||No|
One of my goals for my websites, including this one, is to look presentable both in print and on a handheld. Well, I found out today that this blog doesn’t look so hot in either mode. I also found out that my tool for rounding corners (a jQuery plugin) runs even when in print mode. So I’ve got to change my site to use CSS so the rounded corners don’t show up in print mode.
(If you hover over “CSS” you’ll see that I’m using the abbr tag. For a good article of abbr vs. acronym, read this.)