24 Votes

TinyMCE: Check if TinyMCE is available

Question by Guest | Last update on 2021-04-06 | Created on 2014-05-06

I would like to show the TinyMCE HTML Editor only to a special group of the users of my website. The normal user is not allowed to use the editor.

So, I include the TinyMCE files dynamically only if necessary.

Because I am using the same JavaScript code for all users, the line with tinymce.init() is also written in the code in cases, TinyMCE is not available at all. So, in this case it, the function is unknown leading to errors when executing the code.

So, what I need is a function to check whether TinyMCE is available on not. Only if it is available, I would run the initialization with tinymce.init(). Is there any possibility to check that?

ReplyPositiveNegative
5Best Answer5 Votes

You can just check whether typeof(tinyMCE) is defined:

if (typeof(tinyMCE) != "undefined") {
  tinymce.init({
    selector: "textarea"
  });
}

Only if typeof(tinyMCE) is not undefined, the tinymce.init() will be executed.
Last update on 2021-04-06 | Created on 2014-05-06

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.