Are you happy to change the domain of the iframe to? The following works (for me) in IE7,9
document.domain = 'jshell.net';
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.src = "javascript:document.write('<script>document.domain=\"jshell.net\"</script>')";
// Now write some content to the iframe
iframe.contentWindow.document.write('<html><body><p>Hello world</p></body></html>');
Edit: If this is inline script on a page then you need to split the closing </script>
tag up. See why-split-the-script-tag