开发者

Saving multiple TinyMCE instances

I have multiple instances of TinyMCE on one page.

I have a javascript autosave running in the background that automatically saves the forms in the database via a POST request. This works good with one form where I can set the element ID in the init. However, in m开发者_JAVA百科y scenario, the user can have a variable number of TinyMCE forms, so having multiple hardcoded element ID's do not seem practical.

TL;DR: Dynamically grab all instances of TinyMCE in the same page without knowing the instance ID. Or, any other approach to save multiple forms in one auto_save() function.


The way Brett decribed is correct. Here is the code you may call whenever needed, i.e. in your auto_save() function:

for (var i = 0; i < tinymce.editors.length; i++) {
    // you need to do what is needed here
    // example: write the content back to the form foreach editor instance
    tinymce.editors[i].save();
}


You could iterate through the tinyMCE.editors collection in your auto_save() function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜