title: Change Iframe Style When the Src is Set Dynamically
body: <p>In my site I have this iframe </p>
  
  <pre><code>&lt;iframe id='iFrameName1' width='1000' height='500'&gt;&lt;/iframe&gt;
  </code></pre>
  
  <p>The src tag is dynamically defined with javascript. In addition, I want to dynamically change the style of the iframe (it is in the same domain). </p>
  
  <pre><code>&lt;script&gt; function urlChange() {      
  var iframe1 = document.getElementById('iFrameName1'); 
  iframe1.src = 'mypage.html';
  var cssLink = document.createElement("link"); 
  cssLink.href = "iframe.css";  
  cssLink.rel = "stylesheet";  
  cssLink.type = "text/css"; 
  iframe1.contentDocument.getElementsByTagName('head')[0].appendChild(cssLink); 
  }  
  &lt;/script&gt;
  </code></pre>
  
  <p>The problem is: as the src is defined dynamically, I think the "iframe1.contentDocument" is not found.</p>
  
  <p>How to solve this problem? I want to define the src and to change the iframe style dynamically.</p>
  
  <p>Thanks in advance.</p>