W3C home > Mailing lists > Public > public-html@w3.org > November 2007

Re: Whitespace before <head>

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Fri, 16 Nov 2007 11:09:37 -0800
Message-ID: <c9e12660711161109n4f78beh36b83ca1dca893d5@mail.gmail.com>
To: "Boris Zbarsky" <bzbarsky@mit.edu>
Cc: "Chris Wilson" <Chris.Wilson@microsoft.com>, public-html <public-html@w3.org>

  Changing innerHTML to an element (my second example) with
white-space: pre fails in IE7. (I'll go look up 'blithe' later...)
You can try:

Even using

will fail in IE7. You might be able to get it to work with outerHTML,
but then you'd lose the node reference. To mimic innerHTML, there's a
trick to set the outerHTML and use a regexp.

function setInnerHTML(el, s) {
    if (typeof el.innerHTML != "string") {
        throw new TypeError("setInnerHTML: first argument does not
support innerHTML. Is it an element?");
    if (isIE && /\n/.test(s)) {
        var innerHTML = new RegExp(">([^<]*)<");
        var outerHTML = el.outerHTML;
        var oldContent = outerHTML.match(innerHTML)[1];
        el.outerHTML = outerHTML.replace(oldContent, s);
    } else {
        el.innerHTML = s;

I haven't tried using this on anything other than PRE element and TD.
It failed on TD element.

I really did not like using the isIE variable. It is always a bad idea
to use browser detection and I've learned this the hard way, having to
maintain scripts that use browser detection where the browser's
features change, and where other browsers falsely identify themselves
(most notably Opera identifying as IE).

So in my function, all other browsers get:

el.innerHTML = s;

  That testcase is in BackCompat mode (no uri doctype). Does it work
differently with a URI doctype? I don't know if it's necessary, but
could be tested by using an iframe. This sort of test could be done
with Selenium.

  Glad to see you agree. I read a few posts on the DSTF web site that
said something contradictory. PPK and I think maybe Nicolas. Not sure
who else.

 wow, got a whole can of worms open here :-)

On Nov 16, 2007 9:06 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> Chris Wilson wrote:
> > And please don't be so blithe about Microsoft.  We drop whitespace around the
> > head, and I believe we still have some issue in table cells; in general, the
> > Trident engine was designed to round-trip content, including whitespace.  We
> > could not, as noted, support CSS' white-space:pre if we didn't.
> Chris, last I checked styling a node with "white-space: pre" will actually
> change the DOM in Trident (Text nodes that didn't use to be there will appear).
>   So while I accept that you're keeping the whitespace around _somewhere_
> internally, in practice as far as web authors are concerned you drop all sorts
> of whitespace from the DOM... unless the style happens to be "white-space: pre".
> -Boris

Programming is a collaborative art.
Received on Friday, 16 November 2007 19:09:47 UTC

This archive was generated by hypermail 2.4.0 : Saturday, 9 October 2021 18:44:24 UTC