TypeError: window.tinyMCE.execInstanceCommand is n

2019-04-26 20:26发布

问题:

I can't add any shortcode in my wordpress editor. it shows - Uncaught TypeError: Object [object Object] has no method 'execInstanceCommand' . plesase help me to solve this.

the code(tinymce.js)

    function init() {
    tinyMCEPopup.resizeToInnerSize();
}

function getCheckedValue(radioObj) {
    if(!radioObj)
        return "";
    var radioLength = radioObj.length;
    if(radioLength == undefined)
        if(radioObj.checked)
            return radioObj.value;
        else
            return "";
    for(var i = 0; i < radioLength; i++) {
        if(radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}

function tjshortcodesubmit() {

    var tagtext;

    var tj_shortcode = document.getElementById('tjshortcode_panel');

    // who is active ?
    if (tj_shortcode.className.indexOf('current') != -1) {
        var tj_shortcodeid = document.getElementById('tjshortcode_tag').value;
        switch(tj_shortcodeid)
{
case 0:
    tinyMCEPopup.close();
  break;

case "button":
    tagtext = "["+ tj_shortcodeid + "  url=\"#\" style=\"white\" size=\"small\"] Button text [/" + tj_shortcodeid + "]";
break;

case "alert":
    tagtext = "["+ tj_shortcodeid + " style=\"white\"] Alert text [/" + tj_shortcodeid + "]";
break;

case "toggle":
    tagtext = "["+ tj_shortcodeid + " title=\"Title goes here\"] Content here [/" + tj_shortcodeid + "]";
break;

case "tabs":
    tagtext="["+tj_shortcodeid + " tab1=\"Tab 1 Title\" tab2=\"Tab 2 Title\" tab3=\"Tab 3 Title\"] [tab]Insert tab 1 content here[/tab] [tab]Insert tab 2 content here[/tab] [tab]Insert tab 3 content here[/tab] [/" + tj_shortcodeid + "]";
break;

default:
tagtext="["+tj_shortcodeid + "] Insert you content here [/" + tj_shortcodeid + "]";
}
}

if(window.tinyMCE) {
        //TODO: For QTranslate we should use here 'qtrans_textarea_content' instead 'content'
            window.tinyMCE.execInstanceCommand('content', 'mceInsertContent', false, tagtext);
            //Peforms a clean up of the current editor HTML. 
            //tinyMCEPopup.editor.execCommand('mceCleanup');
            //Repaints the editor. Sometimes the browser has graphic glitches. 
            tinyMCEPopup.editor.execCommand('mceRepaint');
            tinyMCEPopup.close();
        }
        return;
    }

回答1:

I had the same problem. Change your code to this and it should work:

if(window.tinyMCE) {

    /* get the TinyMCE version to account for API diffs */
    var tmce_ver=window.tinyMCE.majorVersion;

    if (tmce_ver>="4") {
        window.tinyMCE.execCommand('mceInsertContent', false, tagtext);
    } else {
        window.tinyMCE.execInstanceCommand('content', 'mceInsertContent', false, tagtext);
    }

    tinyMCEPopup.editor.execCommand('mceRepaint');
    tinyMCEPopup.close();
    }
    return;
}

Note: since .js files are cached, you'll need to do a hard refresh to get this to work. If you are still seeing the same console errors, that would likely be the cause.



回答2:

Scott B's answer is partially innacurate.

The point of execInstanceCommand in TinyMCE version 3 was to execute a command on a specific instance of TinyMCE in the document. Calling execCommand without specifying an instance will either use the focused instance or the first instance in the document, if none is currently focused.

To specify the instance you would like to execute your command on in TinyMCE version 4, call execCommand on the desired editor instance like so:

tinyMCE.get(editorId).execCommand(...);


标签: tinymce-3