Singpolyma

Technical Blog

JSONP in IE

Posted on

Another post based on a previous tweet. This took me at least an hour to debug, so I thought it might be worthwhile sharing.

IE, apparently, gets unhappy when you append nodes to the end of a node it hasn’t finished rendering yet. In practice, this means it blows up when you say document.body.appendChild before the page has loaded. The easy solution? Append to a node that has already loaded! What node is almost guaranteed to be there when the body is rendering? The head node of course! Here is code:

document.getElementsByTagName('head')[0].appendChild(script);

Leave a Response