Hast du mal ein Online-Beispiel, an dem man das ganze nachvollziehen kann?
Hm. Ich hab jetzt mal ein simples Beispiel gebaut, das im Prinzip dieselbe Funktionalität hat, mit dem tritt aber interessanterweise der Fehler nicht auf. D.h. vermutlich ist das irgendeine Interaktion mit anderen Code-Elementen. Werde also nochmal debuggen müssen. Das (funktionierende) Beispiel sieht dann so aus:
<html>
<head></head>
<body>
<textarea id="test2">
Zeile 1
Zeile 2
</textarea>
<script type="text/javascript">
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.contentWindow.document.open();
iframe.contentWindow.document.write('<html><head><title></title></head><body></body></html>');
iframe.contentWindow.document.close();
iframe.contentDocument.designMode='On'
var iframe_body =
iframe.contentWindow.document.getElementsByTagName('body')[0];
iframe_body.style.fontFamily = 'monospace';
iframe_body.style.whiteSpace = 'pre';
iframe_body.innerHTML = document.getElementById('test2').value;
</script>
</body>
</html>