Insert in place without document.write. Very neat trick, but I’d like to see more extensive reports on browser compatibility before committing to it.
Insert in place without document.write. Very neat trick, but I’d like to see more extensive reports on browser compatibility before committing to it.
document.write()is not needed. They also work in every browser in popular use today, so I wouldn't worry so much about the browser compatibility. DOM2 is pretty much universally supported, at least in a way that makes this script work flawlessly across the board.IMO, the biggest disadvantage of document.write isn't that it currently doesn't work in XHTML, but that it relies on the script being loaded in-place in a blocking manner. By "blocking" I mean that while the script loads, the browser can't continue laying out the page or even parsing to find out what other resources (images, scripts, etc) need to be fetched. By "in-place" I mean that the script is included at the point in the document where the script adds content, rather than at the end of the document or in the head using the DEFER attribute.
Sam's trick also relies on in-place, blocking script loads, so I don't think it's the best solution.
It's too bad that Google AdSense insists on using document.write. I'm not comfortable using AdSense anywhere other than the bottom of my page as a result. Why can't I just reference the iframe directly from my page?
Jesse Ruderman - 12th July 2007 11:28 - #
Please add https to your whitelist for the "href" attribute in comments. I had to change the bug link from https to http to make your blog stop rejecting it.
Jesse Ruderman - 12th July 2007 11:29 - #
It's in the Gecko DOM reference and on MSDN as being supported by IE5+, which leaves Safari and uncaught exceptions in IE.
(I'd hope.)
ben - 12th July 2007 12:54 - #
Josh Clark - 12th July 2007 14:07 - #
I tested that technique in IE5 (windows and mac), IE5.5, 6 & 7, Safari 1.3 and 3b, Opera 9, and Firefox 2. It worked in all, however generating an iframe with it didn't work in IE5.0
brothercake - 13th July 2007 01:28 - #