Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To get the button inside of the iframe, this could work:</p> <pre><code>var iframe = document.getElementById("frame1"); var iframeDocument = iframe.contentDocument || iframe.contentWindow.document; var button = iframeDocument.getElementById("mybutton"); </code></pre> <p>Obviously, you can navigate to get what you want with <code>iframeDocument</code>, and use <code>.innerHTML</code> as you seem to know. You cannot get the contents of the iframe if the iframe is pointing to a domain other than its parent.</p> <p><strong>UPDATE:</strong></p> <p>You need to use the code to get the frame's document and its contents <strong>after</strong> it's ready, so you should use something like this:</p> <pre><code>window.onload = function () { var greeting = "hola, "; var div1 = document.createElement("div"); var frame1 = document.createElement("iframe"); frame1.id = "frame1"; frame1.onload = function () { alert("loaded"); var iframe = document.getElementById("frame1"); var iframeDocument = iframe.contentDocument || iframe.contentWindow.document; var button = iframeDocument.getElementById("mybutton"); if (button == null) { alert("button is null"); } }; frame1.src = "http://onemoredemo.appspot.com"; div1.appendChild(frame1); document.body.appendChild(div1); }; </code></pre> <p><strong>DEMO:</strong> <a href="http://jsfiddle.net/nqTnz/" rel="nofollow">http://jsfiddle.net/nqTnz/</a></p> <p>The important thing is how the elements are created and appended to the DOM - not just using <code>innerHTML</code>. The <code>onload</code> method of the iframe is to guarantee it's ready. The actual manipulation code won't work in the jsFiddle because the cross-domain problems, but is what you should need.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload