IE javascript html encoding weirdness
Put this in your location bar in IE
javascript:location.href='http://www.google.com/search?q=something<=bar'
Watch in horror as it helpfully thinks <
actually means <
and makes it a <
.
WTF is going on here?
Other browsers don't do开发者_C百科 this. How do I prevent IE from doing this?
Since this is part of an HTML document you should escape the & by replacing it by &
An ampersand '&' in HTML mark the start of a character reference entity such as < > and é
Literal ampersands in your document should be written as &
Note that if that code is generated dynamical you should also escape the URL so that it can appear in a JavaScript string as well.
Edited: I can confirm this particular problem occurs when pasting JavaScript code directly in the address bar. It seems HTML character escaping rules are irrelevant here after all.
I've googled a bit and found this blog post which identify that particular behavior as an ie bug.
精彩评论