Re: Whitespace before <head>

Chris:
  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:
javascript:void(document.body.innerHTML="Garrett\nSmith")
javascript:void(document.body.style.whiteSpace="pre")

Even using
javascript:void(document.body.innerHTML="Garrett\r\nSmith")

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;


Simon:
  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.

Nick,
  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.

Anne,
 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