Guillermo Phillips
Guillermo Phillips

Reputation: 2216

IE HTML Escaping

I have a little problem that's driving me mad. I have the following example code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <script>
        function Test() {
            document.getElementById("test").innerHTML = "<input type='text' value='ab&apos;cef'>"
        }
    </script>
    <body>
        <div id="test"></div>
    </body>
    <script>
        Test();
    </script>
</html>

This example works great in FireFox 3.5, and I get to see an apostrophe in the middle of the text in the Input box. However, IE 7 displays it verbatim as: ap&apos;cef.

I've variously tried different escaping in the vain hope of seeing the apostrophe, for example \x27 or \' without any success. Does any clever person know how to do it in IE?

I realise I could use DOM methods to create nodes, but there's too much code for me to refactor it all.

Thanks!

Upvotes: 1

Views: 192

Answers (2)

Matthew Wilson
Matthew Wilson

Reputation: 3929

document.getElementById("test").innerHTML = "<input type=\"text\" value=\"ab'cef\">"

Upvotes: 0

Quentin
Quentin

Reputation: 943981

&apos; is an XML feature. It isn't allowed in HTML 4.x and isn't supported by Internet Explorer. Firefox supports it as part of its tag soup parser to cope with XHTML being served as text/html.

Use &#39; instead.

See also XHTML 1.0 Appendix C.

Upvotes: 4

Related Questions