<p>I have a multi-frame layout. One of the frames contains a form, which I am submitting through XMLHttpRequest. Now when I use document.write() to rewrite the frame with the form, and the new page I am adding contains any javascript then the javascript is not exectuted in IE6?</p>

<p>For example:</p>

<pre><code>document.write("&lt;html&gt;&lt;head&gt;&lt;script&gt;alert(1);&lt;/script&gt;&lt;/head&gt;&lt;body&gt;test&lt;/body&gt;&lt;/html&gt;");
</code></pre>

<p>In the above case the page content is replaced with test but the alert() isn't executed. This works fine in Firefox.</p>

<p>What is a workaround to the above problem? </p>

[{'answer_id': 69655, 'author': 'dimarzionist', 'author_id': 10778, 'author_profile': 'https://Stackoverflow.com/users/10778', 'pm_score': 1, 'selected': False, 'text': "<p>Workaround is to programmatically add <code>&lt;script&gt;</code> blocks to head DOM element in JavaScript at Callback function or call eval() method. It's only way you can make this work in IE 6.</p>\n"}, {'answer_id': 69662, 'author': 'dimarzionist', 'author_id': 10778, 'author_profile': 'https://Stackoverflow.com/users/10778', 'pm_score': 0, 'selected': False, 'text': '<p>Another possible alternative is to use JSON, dynamically adding scripts references which will be automatically processed by browser. </p>\n\n<p>Cheers.</p>\n'}, {'answer_id': 159789, 'author': 'Armin Ronacher', 'author_id': 19990, 'author_profile': 'https://Stackoverflow.com/users/19990', 'pm_score': 0, 'selected': False, 'text': "<p>In short: You can't really do that.  However JavaScript libraries such as jQuery provide functionality to do exactly that.  If you depend on that, give jQuery a try.</p>\n"}, {'answer_id': 159830, 'author': 'cllpse', 'author_id': 20946, 'author_profile': 'https://Stackoverflow.com/users/20946', 'pm_score': 0, 'selected': False, 'text': "<p>Eval and/or executing scripts dynamically is bad practice. Very bad practice. Very, very, very bad practice. I can't stress enough, how bad practice it is.</p>\n\n<p>AKA.: Sounds like bad design. What problem are you trying to solve again?</p>\n"}, {'answer_id': 159840, 'author': 'Ates Goral', 'author_id': 23501, 'author_profile': 'https://Stackoverflow.com/users/23501', 'pm_score': 1, 'selected': False, 'text': '<p>Instead of having the JS code out in the open, enclose it in a function (let\'s call it "<code>doIt</code>"). Your frame window (let\'s say it\'s name is "formFrame") has a parent window (even if it\'s not visible) in which you can execute JS code. Do the actual frame rewrite operation in that scope:</p>\n\n<pre><code>window.parent.rewriteFormFrame(theHtml);\n</code></pre>\n\n<p>Where <code>rewriteFormFrame</code> function in the parent window looks something like this:</p>\n\n<pre><code>function rewriteFormFrame(html) {\n    formFrame.document.body.innerHTML = html;\n    formFrame.doIt();\n}\n</code></pre>\n'}, {'answer_id': 1575755, 'author': 'Ollie Saunders', 'author_id': 113019, 'author_profile': 'https://Stackoverflow.com/users/113019', 'pm_score': 0, 'selected': False, 'text': '<p>You could use an onload attribute in the body tag (<code>&lt;body onload="jsWrittenLoaded()"&gt;</code>).</p>\n'}]
['https://Stackoverflow.com/questions/69546', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']