Javascript 如何判断tinyMCE是否已经启动?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6287350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to tell if tinyMCE has been initated?
提问by Song
I initiate the tinyMCE like this in multiple tabs of JQuery:Tab. But I find to init tinyMCE multiple times yields readonly text areas. Thus I wish to check if tinyMCE is already initated. Is there a method like isInitated() or something similarly convenient there?
我在 JQuery:Tab 的多个选项卡中像这样启动 tinyMCE。但我发现多次初始化 tinyMCE 会产生只读文本区域。因此,我想检查是否已经启动了 tinyMCE。有没有像 isInitated() 这样的方法或类似的方法?
tinyMCE.init({
mode : "textareas",
theme : "simple",
width : "500",
height : "300"
});
回答by Thariama
You can use tinymce.editors.length
to see if there is already an editor instance initalized (tinymce.editors.length > 0
).
您可以使用tinymce.editors.length
来查看是否已经初始化了一个编辑器实例 ( tinymce.editors.length > 0
)。
回答by Yurui Zhang
I know this question is old, but...in case someone is still looking for the holy grail:
我知道这个问题很老,但是……以防万一有人仍在寻找圣杯:
in tinymce 4, you can pass a callback to tinyMCE.init like so:
在 tinymce 4 中,您可以像这样将回调传递给 tinyMCE.init:
tinyMCE.init({
//your regular parameters here...
setup: function(editor) {
editor.on('init', function() {
//all your after init logics here.
});
}
});
回答by YuC
You can add init_instance_callback
to init()
parameters. This callback will be invoked when the tinymce instance is already inited.
您可以添加init_instance_callback
到init()
参数。当 tinymce 实例已经初始化时将调用此回调。
回答by Hakan F?st?k
I am using tincyMCE 4.7.2
I tried the answer of @Thariama and it did not work for me, I guess because his answer is valid for the older versions of the tinyMCE.
我正在使用 tincyMCE 4.7.2
我尝试了@Thariama 的答案,但它对我不起作用,我猜是因为他的答案对旧版本的 tinyMCE 有效。
here is what worked for me (again, according to the version you are working on, this could not be helpful for you)
这是对我有用的(同样,根据您正在使用的版本,这对您没有帮助)
if (tinymce.initialized === true)
回答by Claudiu D.
To check if "tinyMCE" is set just use this:
要检查是否设置了“tinyMCE”,只需使用以下命令:
if(typeof(tinyMCE) != "undefined") {}
回答by GigolNet Guigolachvili
Try this:
尝试这个:
if (typeof(tinymce.activeEditor.contentDocument) !== "undefined") {
// initialized
}
回答by Volmarg Reiso
I found other solution for this.
我为此找到了其他解决方案。
Let's say that You've got element
假设你有元素
<textarea id="tinymce0"></textarea>
Now let's say that You initialize it:
现在让我们说你初始化它:
let config = { selector : '#tinymce0'};
tinymce.init(config);
After that You can make this:
之后你可以做这个:
let tinmyMceInstance = tinymce.get('tinymce0');
if( tinmyMceInstance === null ){
// Your code if not initialized
}
Keep in mind:
记住:
- this works only with id, seems like using classnamefor
get()
won't work
- 这仅适用于ID,似乎是用类名的
get()
将无法正常工作
Works in:
工作于:
{
releaseDate: "2019-05-09",
majorVersion: "5",
minorVersion: "0.5",
}
So it's probably: 5.5
所以它可能是:5.5