title: Insert Iframe Into a Div Using Javascript - for Greasemonkey
body: <p>I need to insert an iframe into a div using javascript.  I need this written in javascript so I can use the code in a greasemonkey script (and greasemonkey only allows for javascript).</p>
  
  <p>The greasemonkey script will be inserting AOL's search bar into various websites.  I've included the working HTML code below so you can test it out to see what the end result is when this works.</p>
  
  <p>Here is exactly what I need to do, written in HTML:</p>
  
  <pre><code>&lt;div style="overflow: hidden; width: 564px; height: 43px; position: relative;"&gt;
  &lt;iframe src="http://aol.com" style="border: 0pt none ; left: -453px; top: -70px; position: absolute; width: 1440px; height: 775px;" scrolling="no"&gt;&lt;/iframe&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I need to make that HTML code work in greasemonkey, which requires it being written in javascript.  Here is what I've got so far (with my final question beneath the "pseudo-code"):</p>
  
  <pre><code>var makeIframe = document.createElement("iframe");
  makeIframe.setAttribute("src", "http://aol.com");
  makeIframe.setAttribute("scrolling", "no");
  makeIframe.setAttribute("border", "0pt");
  makeIframe.setAttribute("border", "none");
  makeIframe.setAttribute("left", "-453px");
  makeIframe.setAttribute("top", "-70px");
  makeIframe.setAttribute("position", "absolute");
  makeIframe.setAttribute("width", "1440px");
  makeIframe.setAttribute("height", "775px");
  makeIframe.setAttribute("scrolling", "no");
  
  var makediv = document.createElement("div");
  makediv.setAttribute("height", "43px");
  makediv.setAttribute("width", "564px");
  makediv.setAttribute("position", "relative");
  makediv.setAttribute("overflow", "hidden");
  </code></pre>
  
  <p>I already know how to either insert the iframe OR insert the div into the source code of the sites I need to insert it into, by doing this:</p>
  
  <pre><code>var getRef = document.getElementById("div-id-to-insert-element-before");
  var parentDiv = getRef.parentNode;
  parentDiv.insertBefore(iframe OR div, getRef);
  </code></pre>
  
  <p>What I CAN'T figure out how to do, is how to write the iframe INTO the div and then insert that div into the source code.  That very last code snippet works for inserting either the div or the iframe into the source code, but I need the iframe inside the div, and then for that div to be inserted into the source code (using that last code snippet).</p>
  
  <p>Any ideas?</p>