Search code examples
javascriptjquerytinymce

is there a way to load an external javascript file inside the tinymce iframe?


Is there a simple way to load external javascript that will work inside of a TinyMCE iframe?

The only thing I've found (that might be the answer) is this: http://www.tinymce.com/wiki.php/API3:class.tinymce.dom.ScriptLoader

But I'm not sure how to load this properly or if it works at all. I tried to load it before and after the tinymce.init directive, even inside it, but nothing seems to work. Just wondering how to intiailize the "ScriptLoader" function.


Solution

  • You may use the scriptloader using the setup init configuration paramter

    tinyMCE.init({
       ...
       setup : function(ed) {
          ed.onInit.add(function(ed, evt) {
    
            // Load a script from a specific URL using the global script loader
            tinymce.ScriptLoader.load('somescript.js');
    
            // Load a script using a unique instance of the script loader
            var scriptLoader = new tinymce.dom.ScriptLoader();
    
            scriptLoader.load('somescript.js');
    
          });
       }
    });