How can I read a ckeditor textbox instead of a normal textbox? My code has the ckeditor code that I tried (but do
This is the code that reads the textbox from an iframe (jsfiddle: http://jsfiddle.net/RTBJQ/12/):
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Copy to iframe 1 to iframe 2</title>
</head>
<body>
<iframe src="http://fiddle.jshell.net/W88j8/show/" id="iframe1" height="600" width="500"></iframe>
<button id="copyButton">Copy</button>
<iframe id="iframe2" height="600" width="500"></iframe>
<script>
window.onload = function(){
var iframe1 = document.getElementById('iframe1');
var iframe2 = document.getElementById('iframe2');
//After you will be able to use the DOM of the 2 iframes to read content
var oDoc1 = (iframe1.contentWindow || iframe1.contentDocument);
if (oDoc1.document) oDoc1 = oDoc1.document;
var oDoc2 = (iframe2.contentWindow || iframe2.contentDocument);
if (oDoc2.document) oDoc2 = oDoc2.document;
//Where we gonna output the datas
var outputBody = oDoc2.body;
var copyButton = document.getElementById('copyButton');
copyButton.onclick = function(){
var inputs = oDoc1.getElementsByTagName('textarea');
//var inputs = iframe1.CKEDITOR.instances.test6.getData();
//console.log(typeof inputs); console.log(inputs.toString());
outputBody.innerHTML = '<div>';
for (var i = 0 ; i < inputs.length ; i++){
outputBody.innerHTML += '<div>'+inputs[i].value+'</div>';
}
outputBody.innerHTML += '</div>';
};
};
</script>
</body>
</html>
I think this line that reads the textarea should be fixed (line 27 on jsfiddle):
var inputs = oDoc1.getElementsByTagName('textarea');
This is what I have tried, but it doesn't work (line 28 on jsfiddle [commented]):
var inputs = iframe1.CKEDITOR.instances.test6.getData();
This is the type of textarea (ckeditor) it should read, this is the HTML code in iframe #1:
<script type="text/javascript" src="http://nightly.ckeditor.com/13-10-29-07-05/standard/ckeditor.js"></script>
<textarea class="ckeditor" id="test6" name="testa">asdfasdf</textarea>
Thanks.