In IE, the document is not displayed and is not created automatically, so you need to create it before accessing it:
var $frame = $('<iframe />').css({ position: 'fixed', top: 0, left: 0, width: '100%', height: '100%' }).appendTo('body'); var doc = $frame[0].contentDocument || $frame[0].contentWindow.document; doc.open(); doc.write("<!DOCTYPE html><html><head><title></title></head><body></body></html>"); doc.close(); $('head').children().appendTo($frame.contents().find('head')); $('body').children().not($frame).appendTo($frame.contents().find('body'));
DEMO: http://jsfiddle.net/XAMTc/show/
This seems to work in IE8 / 9, as well as the latest Firefox and Chrome, at least.
The way I figured out the problem is console.log ging $frame.contents().find('head').length , which was 0 in IE.
source share