Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.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 获取编辑器元素的高度_Javascript_Ckeditor - Fatal编程技术网

Javascript 获取编辑器元素的高度

Javascript 获取编辑器元素的高度,javascript,ckeditor,Javascript,Ckeditor,我在一页上有一个编辑。每当用户通过拖动编辑器更改高度时,我都想知道新高度,以便保存它 使用CKEDITOR.config.height可以获得配置的高度,但需要当前高度 我也尝试过使用jQuery中的height(),但这只会通过CSS提供高度集,如果没有高度集,则会提供“43” 我也愿意 获取CKEditor文本区域的当前高度(减去菜单,但我可以自己计算) 当高度变化时,让CKEditor触发某个事件 原因是,我希望将此信息与内容一起保存,以便正确显示iframe的大小 要获取当前高度,可

我在一页上有一个编辑。每当用户通过拖动编辑器更改高度时,我都想知道新高度,以便保存它

使用
CKEDITOR.config.height
可以获得配置的高度,但需要当前高度

我也尝试过使用jQuery中的height(),但这只会通过CSS提供高度集,如果没有高度集,则会提供“43”

我也愿意

  • 获取CKEditor文本区域的当前高度(减去菜单,但我可以自己计算)
  • 当高度变化时,让CKEditor触发某个事件
原因是,我希望将此信息与内容一起保存,以便正确显示iframe的大小

  • 要获取当前高度,可以使用:

    editor.ui.space( 'contents' ).getStyle( 'height' ); // e.g. 200px
    
    这将查找名为contents的UI空间,contents是放置可编辑iframe的元素。当您通过方法设置编辑器的高度时,此大小直接在内容UI空间上设置

  • 当编辑器大小更改时,您可以侦听事件以执行某些代码:

    editor.on( 'resize', function() {
        console.log( 'resized...' );
    } );
    
  • 注:此答案适用于CKEditor 4.0。它可能无法在CKEditor 3.6.x上工作

  • 要获取当前高度,可以使用:

    editor.ui.space( 'contents' ).getStyle( 'height' ); // e.g. 200px
    
    这将查找名为contents的UI空间,contents是放置可编辑iframe的元素。当您通过方法设置编辑器的高度时,此大小直接在内容UI空间上设置

  • 当编辑器大小更改时,您可以侦听事件以执行某些代码:

    editor.on( 'resize', function() {
        console.log( 'resized...' );
    } );
    

  • 注:此答案适用于CKEditor 4.0。如果要查找整个“经典”CKEditor(带工具栏)的高度,它可能无法在CKEditor 3.6.x上工作。请尝试:


    其中
    editor
    指向一个CKEditor实例。

    如果要查找整个“经典”CKEditor(带工具栏)的高度,请尝试:


    其中
    editor
    指向CKEditor实例。

    此代码使用JQuery在“经典编辑器”(带工具栏)中获取文档正文的高度“编辑器”是CKEDITOR的一个实例:

    CKEDITOR.on( 'instanceReady', function( evt )
      {
        var editor = evt.editor;
    
       editor.on('change', function (e) { 
        var contentSpace = editor.ui.space('contents');
        var ckeditorFrameCollection = contentSpace.$.getElementsByTagName('iframe');
        var ckeditorFrame = ckeditorFrameCollection[0];
        var innerDoc = ckeditorFrame.contentDocument;
        var innerDocTextAreaHeight = $(innerDoc.body).height();
        console.log(innerDocTextAreaHeight);
        });
     });
    

    参考资料:


    此代码使用JQuery在“经典编辑器”(带工具栏)中获取文档正文的高度“编辑器”是CKEDITOR的一个实例:

    CKEDITOR.on( 'instanceReady', function( evt )
      {
        var editor = evt.editor;
    
       editor.on('change', function (e) { 
        var contentSpace = editor.ui.space('contents');
        var ckeditorFrameCollection = contentSpace.$.getElementsByTagName('iframe');
        var ckeditorFrame = ckeditorFrameCollection[0];
        var innerDoc = ckeditorFrame.contentDocument;
        var innerDocTextAreaHeight = $(innerDoc.body).height();
        console.log(innerDocTextAreaHeight);
        });
     });
    

    参考资料: