如何调用TinyMCE插件function?

如何调用tinymce插件函数?

tinymce.activeEditor.plugins.customplugin.customfunction(customvar); 

不工作!

tinymce.activeEditor.plugins.customplugin.customfunction(customvar);

是调用这样一个函数的正确方法。 请注意,需要设置tinymce.activeEditor才能使用它。 tinymce.activeEditor ,当用户点击编辑器时,会设置tinymce.activeEditor 。 否则使用

 tinymce.get('your_editor_id_here').plugins.customplugin.customfunction(customvar); 

您的函数调用可能还有另一个原因:要调用的函数需要像保存插件中的函数getInfo_save_nodeChange一样定义(请参阅开发人员构建的tinymce来检查插件目录中的这个插件)。

保存插件缩短了:

 (function() { tinymce.create('tinymce.plugins.Save', { init : function(ed, url) { ... }, getInfo : function() { ... }, // Private methods _nodeChange : function(ed, cm, n) { ... }, // Private methods ... _save : function() { } }); // Register plugin tinymce.PluginManager.add('save', tinymce.plugins.Save); })(); 

您可以使用以下javascript调用调用此插件的getInfo函数:

 tinymce.get('your_editor_id_here').plugins.save.getInfo(); 

将您想要暴露的function放在外面的世界中。

 tinymce.PluginManager.add('myplugin', function(editor) { var self = this; var self.myFunction = myFunction(); // Put function into self! function myFunction() { console.log('Hello world!'); } } 

然后:

 tinymce.get('your_editor_id_here').plugins.myplugin.myFunction();