Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取Iframe中CKEditor的内容_Javascript_Html_Iframe - Fatal编程技术网

Javascript 获取Iframe中CKEditor的内容

Javascript 获取Iframe中CKEditor的内容,javascript,html,iframe,Javascript,Html,Iframe,我有以下代码来显示CKEditor。我可以在html文档中获取和设置数据 <!DOCTYPE html> <html> <head> <script type="text/javaScript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"> </script> <script src="http

我有以下代码来显示CKEditor。我可以在html文档中获取和设置数据

<!DOCTYPE html>
<html>
 <head>

   <script type="text/javaScript" 
        src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
   </script>
   <script src="http://www.wilsea.com/ckeditor/ckeditor.js"></script>

 </head>
 <body>
        <textarea id="editor1" name="editor1" rows="10" cols="80">
            This is my textarea to be replaced with CKEditor2
        </textarea>
   <div id="someID">Hello world!</div>
   <script>
           function myFunction() {
           var html = 'this is my new text from function1 ';
           alert('function 1 test121');
           CKEDITOR.instances['editor1'].setData(html);
           }

           function myFunction2() {
           var editorData = CKEDITOR.instances['editor1'].getData();
           alert('new data' + editorData);
           }
           CKEDITOR.replace( 'editor1' );
   </script>
   <p>Click the button to trigger a function.</p>
   <button onclick="myFunction()">Set Data</button>
   <button onclick="myFunction2()">Get Data</button>
   <p id="demo"></p>
 </body>
</html>
我在Chrome中使用了开发者工具,我看到“id someID”存在,那么我在这里不理解其中的哪一部分

我的目标是能够:

  • 从我的数据库填充CKEditor的html内容
  • 允许客户端编辑/添加图像等
  • 将CKEditor的html内容保存到我的数据库中

  • 我从这里得到了答案:

    关键是DOM元素id不是AC小部件名称。但是,您可以通过以下命令相当容易地获取和使用DOM id(“contextMenu”是本例中iFrame小部件的AC名称)

    它可能与每个人都不相关,因为它特定于应用程序工艺,但思考过程可能会帮助其他人


    MRWarby

    外部站点可以/确实更改。最好在这里说明答案,并附上外部站点的链接作为参考。这样,未来的读者可以随时看到你做了什么,如果你检查你的网页,某些东西正在改变你的Iframe id,比如:Iframe_wwbdbxwqq5ctcgz50ko1eqgfk4szyss94io3,所以你永远无法获得内容。
    <div id="someID">Hello world!</div>.
    
    var HTML1 =  $('#iFrame1').contents().find('#someID').html();
    alert(HTML1);
    
    
    var HTML1 =  $('#iFrame1').contents().find('#editor1').html();
    alert(HTML1);
    
    contextMenuId = 'iframe_' + app.w('contextMenu').base()[0].id; 
    
    document.getElementById(contextMenuId).contentDocument.getElementsByClassName('cke_wysiwyg_frame')[0].contentDocument.body.innerHTML