title: Dynamically changing javascript
body: <p>I want to change the javascript of a page inside iframe. (I don't have cross domain issues)</p>
  
  <p>Say I have two html files:</p>
  
  <p>index.html </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  function change() {
   var text = document.getElementById("text").value;
   
   var html = $("#iframe_id").contents().find("html").html();
   html = html.replace(/---someText---/mg, text);
  
   $("#iframe_id").contents().find("html").html(html);
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  Dynamic Alert Text: &lt;input type="text" id="text" value="" /&gt;
  &lt;input type="button" value="Change Iframe" onclick="change()" /&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;iframe src="iframe.html" id="iframe_id" width="500" height="400"&gt;&lt;/iframe&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>and iframe.html</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script&gt;
  function test() {
   alert("---someText---");
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div&gt;Text is: ---someText---&lt;/div&gt;
  &lt;input type="button" value="Test Me!" onclick="test();" /&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I want to replace alert message of the iframe.html with the text I get from index.html
  Just replacing it doesn't work.
  Is there a work around.</p>