Easy way to inject js in tinymce iframe?

I was wondering if there is any direct hook to inject some javascript into tinymce iframe?

Related posts

Leave a Reply

2 comments

  1. WordPress injects its own external script files in the TinyMCE editor iframe, see for example the wp-includes/js/tinymce/plugins/wpembed/plugin.js file:

    (function ( tinymce ) {
        'use strict';
    
        tinymce.PluginManager.add( 'wpembed', function ( editor, url ) {
            editor.on( 'init', function () {
                var scriptId = editor.dom.uniqueId();
    
                var scriptElm = editor.dom.create( 'script', {
                    id: scriptId,
                    type: 'text/javascript',
                    src: url + '/../../../wp-embed.js'
                } );
    
                editor.getDoc().getElementsByTagName( 'head' )[ 0 ].appendChild( scriptElm );
            } );
        } );
    })( window.tinymce );
    

    The plugin.js file is loaded in TinyMCE using the tiny_mce_plugins filter.