【问题标题】:CKEditor inline editor on elements within an iframeCKEditor 内联编辑器在 iframe 中的元素上
【发布时间】:2013-10-17 00:02:11
【问题描述】:

在一个应用程序中,我在 iframe 中有内容可编辑元素,并希望将内联 CKEditor 应用于这些元素。它可以工作,除非当我滚动 iframe 时,CKEditor 工具栏不会随之滚动。是否有特殊标志或某种方法可以使工具栏随 iframe 内容而不是父窗口滚动?另外我想避免将 CKEditor 脚本添加到 iframe 中。

【问题讨论】:

  • 值得一提的是我们对 CKEditor 的错误跟踪器的讨论:dev.ckeditor.com/ticket/11003
  • 你能分享你用来让内联编辑器处理 iframe 中的元素的代码吗?我对此有疑问

标签: javascript html iframe ckeditor


【解决方案1】:

您可以通过使用与 iframe 大小相同且具有相对定位的容器元素包装 iframe 来实现此目的。

<div id="iframe-wrapper">
    <iframe>
        <body>
            <div contenteditable></div>
        </body>
    </iframe>
</div>

然后将每个 ckeditor 面板的位置移动到该容器元素中,绝对定位值将起作用。

var el = $('iframe').contents().find('[contenteditable]');
el.ckeditor();
el.ckeditorGet().on('instanceReady', function(){
    $('body > .cke_float').appendTo('#iframe-wrapper');
});

【讨论】:

  • 我自己没有尝试过,但是当 iframe 滚动时这是否有效?
  • 不,这仅在 iframe 高度固定为与容器相同的高度时才有效。虽然,我确信您可以滚动 iframe 并以这种方式进行计算,但是您还必须处理当元素超出 iframe 屏幕边界时发生的情况。
  • @georgephillips 请您将此答案标记为正确
猜你喜欢
  • 1970-01-01
  • 2020-12-09
  • 1970-01-01
  • 1970-01-01
  • 2022-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多