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.
home-upload-dialog.php
view file
<div id="popup-contents">
<iframe id="upload-frame" frameborder="0" scrolling="no" height="200" width="100%" src="<?php echo site_url('home/upload_area/' . $_REQUEST['count']);?>"></iframe>
</div>
<input type="button" value="click me" onclick="run()">
<script>
run() {
var iframedoc = document.getElementsByTagName('iframe')[0].contentWindow.document;
var inputs = iframedoc.getElementById('text');
console.log(inputs);
}
</script>
home.php
controller
upload_area() {
$data['count'] = $count;
$this->load->view('upload-area', $data);
}
upload-area.php
view file
<!DOCTYPE html>
<html>
<head>
<title>Title here</title>
</head>
<body>
<input type="text" name="text" id="text" value="someValue">
</body>
</html>
I get the error saying Uncaught TypeError: Cannot read property 'contentWindow' of undefined
There might be things I overlooked. Any help would be appreciated !
I also tried $('iframe').contents().find('#text').html();
but no luck.