18 Aug
Posted by krisgale as compatibility hacks, annoyances, browsers
recently, i could not for the life of me determine why two strings that should have compared as being equal simply refused to do so… that is, until i set up an alert box to display the underlying comparison character-by-character.
you’ll get different output from this script depending on whether you are viewing it from opera, safari, firefox, or internet explorer. the former two convert all instances of the non-breaking space html entity ( ) into its ascii character equivalent (#160)… the latter two leave the html as-is.
pay close attention:
<html><head><title>string comparison</title></head><body><pre><span id="a">A b</span><span id="b">a B</span><script type="text/javascript">var x = document.getElementById("a").innerHTML;var y = document.getElementById("b").innerHTML;x = x.toLowerCase().replace(' ',' ');y = y.toLowerCase();document.writeln(x == y);x = x.replace('\xa0',' ');document.writeln(x == y);</script></pre></body></html>| bookmark it! | ||||||
|
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Jun | ||||||
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | |||
RSS feed for comments on this post · TrackBack URI
Leave a reply