javascript - 向 CKEditor 添加本地插件

标签 javascript ckeditor editor wysiwyg ckeditor4.x

我正在使用 CKEditor4 完整版并使用 CDN:

<script src="//cdn.ckeditor.com/4.10.0/full/ckeditor.js"></script>

我想向 CKEditor 添加额外的插件,我下载了文件并想添加它们。

我尝试过:

CKEDITOR.plugins.addExternal( 'simplebutton', 'http://localhost/ckeditor/plugins/simplebutton', 'plugin.js' );
CKEDITOR.replace( 'editor', {
     extraPlugins: 'simplebutton',
     toolbar: [
         { name: 'simplebutton', items: [ 'simplebutton' ] }
     ]
});

但是我收到这些错误:

Uncaught SyntaxError: Unexpected token <   ?t=I63Cplugin.js:1 

Uncaught TypeError: Cannot read property 'icons' of null  ckeditor.js:264
at CKEDITOR.resourceManager.<anonymous> (ckeditor.js:264)
at CKEDITOR.resourceManager.<anonymous> (ckeditor.js:263)
at e (ckeditor.js:258)
at Array.y (ckeditor.js:258)
at v (ckeditor.js:258)
at ckeditor.js:259

我会添加其他插件。

这是因为我必须输入现有的工具栏选项,然后添加新按钮吗?

最佳答案

造成这种情况的原因可能有多种。

初见 addExternal API 文档:

// Loads a plugin from '/myplugins/sample/plugin.js'.
CKEDITOR.plugins.addExternal( 'sample', '/myplugins/sample/' );

// Loads a plugin from '/myplugins/sample/my_plugin.js'.
CKEDITOR.plugins.addExternal( 'sample', '/myplugins/sample/', 'my_plugin.js' );

// Loads a plugin from '/myplugins/sample/my_plugin.js'.
CKEDITOR.plugins.addExternal( 'sample', '/myplugins/sample/my_plugin.js', '' );

请注意,每个示例都有一个尾部 /字符,所以尝试使用 CKEDITOR.plugins.addExternal( 'simplebutton', '//localhost/plugins/simplebutton/', 'plugin.js' );相反。

如果仍然不起作用,请确保您的网络服务器实际上返回了正确的内容,因为SyntaxError: Unexpected token <看起来好像是 HTML 而不是 HTML。您可以使用浏览器网络检查器来检查。

关于javascript - 向 CKEditor 添加本地插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51908490/

相关文章:

javascript - Javascript 和 Node 中的 JSON 解析

javascript - 我的网格制作器中的错误

javascript - 查找已提交表单的所有提交按钮

plugins - CKEditor-保存多个可编辑的内容-剥离的Divs

javascript - 如何在所见即所得模式下滚动 CKEditor?

css - Aptana,CSS 编辑器(配置)

html - 括号 - 实时预览不工作

javascript - 在 Alfresco 中,有没有办法从 java 脚本取消部署定义?

button - ckeditor动态更改按钮图标

ide - Geany 0.20 上的语法检查/更正