Which whitespace was that again?
We recently saw this at
$WORK. It appears corrupted in Internet Explorer only. Firefox and Safari show it normally.
After much exploration in the debugger, we eventually found it was caused by using the
innerText property in internet explorer. This has the mildly surprising property of turning multiple spaces into U+00A0 (NO-BREAK SPACE) characters (
to you and me). This behaviour doesn’t appear to be documented. And before you ask, this was all being done by a third-party — I know to not use proprietary extensions where possible.
Anyway, I nailed it down to a small test. Given this markup.
Then this script demonstrates the problem.
var foo = document.getElementById('foo'); // OK foo.innerText = ['A', ' ', 'B'].join(''); alert(foo.innerHTML); // "A B" // FAIL foo.innerText = ['A', ' ', ' ', 'B'].join(''); alert(foo.innerHTML); // "A B"
The quick solution is simple: normalize whitespace before insertion before using innerText.
var text = 'some where over the rainbow'; foo.innerText = text.split(/\s+/).join(' ');