How to access data within an iframe?
<p>I have been trying to access data from an iframe. I am working on codeigniter. I have spent my whole day searching for the solution, but no luck. I am not an expert in javascript, so it is becoming more difficult to me. Please have a look at my code.</p>

<p><code>home-upload-dialog.php</code> view file</p>

<pre><code>&lt;div id="popup-contents"&gt;
    &lt;iframe id="upload-frame" frameborder="0" scrolling="no" height="200" width="100%" src="&lt;?php echo site_url('home/upload_area/' . $_REQUEST['count']);?&gt;"&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;input type="button" value="click me" onclick="run()"&gt;
&lt;script&gt;
    run() {
        var iframedoc = document.getElementsByTagName('iframe')[0].contentWindow.document;
        var inputs = iframedoc.getElementById('text');
        console.log(inputs);
    }
&lt;/script&gt;
</code></pre>

<p><code>home.php</code> controller</p>

<pre><code>upload_area() {
    $data['count'] = $count;
    $this-&gt;load-&gt;view('upload-area', $data);
}
</code></pre>

<p><code>upload-area.php</code> view file</p>

<pre><code>&lt;!DOCTYPE html&gt;
    &lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Title here&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;input type="text" name="text" id="text" value="someValue"&gt;
    &lt;/body&gt;
    &lt;/html&gt;
</code></pre>

<p>I get the error saying <code>Uncaught TypeError: Cannot read property 'contentWindow' of undefined</code>
There might be things I overlooked. Any help would be appreciated !</p>

<p>I also tried <code>$('iframe').contents().find('#text').html();</code> but no luck.</p>