简体   繁体   English

获取当前CKEDITOR实例的iframe元素

[英]Get iframe element of current CKEDITOR instance

CKEditor 4 or above CKEditor 4或以上
I have a CKEDITOR instance that I can access without problem parent.CKEDITOR.instances[instance_id] 我有一个CKEDITOR实例,可以正常访问parent.CKEDITOR.instances[instance_id]
I want to add bootstrap file to the head of the iframe generated by CKEDITOR (kind of hack, because normal way to add optional css file was not working). 我想将引导文件添加到由CKEDITOR生成的iframe的头部(有点破解,因为添加可选css文件的常规方法无法正常工作)。
I tried to get the iframe head and to inject the bootstrap file, but it fails always. 我试图获取iframe头并注入bootstrap文件,但是它总是失败。
Any Suggestion? 有什么建议吗?

If you are using classic editor with contents in iframe then please use contentsCss configuration setting to add extra CSS to editor contents area. 如果您将经典编辑器与iframe中的内容一起使用,请使用contentsCss配置设置向编辑器内容区域添加额外的CSS。 It is important to refresh the cache with Ctrl+F5. 使用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 . 如果由于某种原因未应用更改并且CSS文件的路径正确(在浏览器dev-tools控制台中未获取404),则您可能想尝试根据此链接清除缓存。

If you really need to get to the iframe, you can use below technique. 如果您确实需要使用iframe,可以使用以下方法。 It gets you the div with editor id you need and it finds iframe for it. 它为您提供了具有所需editor id的div,并为此找到了iframe This is good if you have couple of editors or iframes on a single page. 如果您在一个页面上有几个编辑器或iframe,这很好。

document.getElementById('cke_'+ your_textarea_id ).getElementsByTagName('iframe')[0].contentWindow

I found it finally, I post it here so maybe it will be helpful for someone in the future. 我终于找到了它,我在这里张贴了它,因此也许将来会对某人有所帮助。
I just added the bootstrap file to the body tag (it is a bad practice but it works). 我只是将bootstrap文件添加到了body标签(这是一种不好的做法,但它可以工作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM