如何阅读 ckeditor 文本框而不是普通文本框?我的代码有我尝试过的 ckeditor 代码(但做
这是从 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>
我认为读取 textarea 的这一行应该是固定的(jsfiddle 上的第 27 行):
var inputs = oDoc1.getElementsByTagName('textarea');
这是我尝试过的,但它不起作用(jsfiddle [commented] 上的第 28 行):
var inputs = iframe1.CKEDITOR.instances.test6.getData();
这是它应该读取的文本区域(ckeditor)的类型,这是 iframe #1 中的 HTML 代码:
<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>
谢谢。