获取当前 CKEDITOR 实例的 iframe 元素
Get iframe element of current CKEDITOR instance
CKEditor 4 或以上
我有一个可以毫无问题地访问的 CKEDITOR 实例 parent.CKEDITOR.instances[instance_id]
我想将 bootstrap 文件添加到 CKEDITOR 生成的 iframe 的头部(有点 hack,因为添加可选 css 文件的正常方法不起作用)。
我试图获取 iframe 头并注入 bootstrap 文件,但它总是失败。
有什么建议吗?
我终于找到了,我 post 把它放在这里,也许它对以后的人有帮助。
我刚刚将 bootstrap 文件添加到正文标签中(这是一种不好的做法,但它有效)。
如果您使用的是带有 iframe 内容的经典编辑器,请使用 contentsCss configuration setting to add extra CSS to editor contents area. It is important to refresh the cache with Ctrl+F5. If for some reason changes are not applied and path to CSS file is correct (you are not getting 404 in browser dev-tools console) then you might want to try clearing cache according to this link。
如果你真的需要访问iframe,你可以使用下面的技巧。它会为您提供 div 和 editor id
您需要的 iframe
。如果您在一个页面上有几个编辑器或 iframe,这很好。
document.getElementById('cke_'+ your_textarea_id ).getElementsByTagName('iframe')[0].contentWindow
CKEditor 4 或以上
我有一个可以毫无问题地访问的 CKEDITOR 实例 parent.CKEDITOR.instances[instance_id]
我想将 bootstrap 文件添加到 CKEDITOR 生成的 iframe 的头部(有点 hack,因为添加可选 css 文件的正常方法不起作用)。
我试图获取 iframe 头并注入 bootstrap 文件,但它总是失败。
有什么建议吗?
我终于找到了,我 post 把它放在这里,也许它对以后的人有帮助。
我刚刚将 bootstrap 文件添加到正文标签中(这是一种不好的做法,但它有效)。
如果您使用的是带有 iframe 内容的经典编辑器,请使用 contentsCss configuration setting to add extra CSS to editor contents area. It is important to refresh the cache with Ctrl+F5. If for some reason changes are not applied and path to CSS file is correct (you are not getting 404 in browser dev-tools console) then you might want to try clearing cache according to this link。
如果你真的需要访问iframe,你可以使用下面的技巧。它会为您提供 div 和 editor id
您需要的 iframe
。如果您在一个页面上有几个编辑器或 iframe,这很好。
document.getElementById('cke_'+ your_textarea_id ).getElementsByTagName('iframe')[0].contentWindow