TypeError:window.tinyMCE.execInstanceCommand不是函数

时间:2014-05-20 作者:user3626111

我无法在wordpress编辑器中添加任何短代码。它显示-

TypeError:窗口。蒂尼姆斯。execInstanceCommand不是函数

窗蒂尼姆斯。execInstanceCommand(id,“mceInsertContent”,false,shortcode)。请帮我解决这个问题。完整代码:-

function submitData($form) {
    try {
        $form = $form || jQuery(\'form\');
        if(window.tinyMCE) {
            var selectedContent = tinyMCE.activeEditor.selection.getContent(),
                id = tinyMCE.activeEditor.editorId || \'content\',
                shortcodeName = $form.attr(\'name\'),
                shortcode = \' [\' + shortcodeName + \' \';

            $form.find(\'[data-name]\').each(function() {
                var $this   =   jQuery(this),
                    type    =   $this.data(\'type\'),
                    value   =   ($this.attr(\'type\') == \'checkbox\')
                            ?   ($this.is(\':checked\')) ? \'on\' : \'\'
                            :   $this.val() || \'\';
                value = fitValue(type, value);
                shortcode += $this.data(\'name\') + \'="\' + value + \'" \';
            });
            shortcode += \']\' + selectedContent + \'[/\' + shortcodeName + \'] \';

            window.tinyMCE.execInstanceCommand(id, \'mceInsertContent\', false, shortcode)
            tinyMCEPopup.editor.execCommand(\'mceRepaint\');
            tinyMCEPopup.close();
        }
    } catch (e) {
        console.error(e);
    }
    return;
}

1 个回复
SO网友:Mr.HTZ

https://stackoverflow.com/questions/22813970/typeerror-window-tinymce-execinstancecommand-is-not-a-function

幸亏Scott B

在Wordpress 3.9中,TinyMCE更新为版本4,在TinyMCE 4中,方法“execInstanceCommand”已被方法“execCommand”替换。

对于兼容性问题(与旧版本的WP),必须检查TinyMCE版本并使用合适的方法。

在下面,我更改了您的代码。注释的代码行是我的。

function submitData($form) {
    try {
        $form = $form || jQuery(\'form\');
        if(window.tinyMCE) {

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

            var selectedContent = tinyMCE.activeEditor.selection.getContent(),
                id = tinyMCE.activeEditor.editorId || \'content\',
                shortcodeName = $form.attr(\'name\'),
                shortcode = \' [\' + shortcodeName + \' \';

            $form.find(\'[data-name]\').each(function() {
                var $this   =   jQuery(this),
                    type    =   $this.data(\'type\'),
                    value   =   ($this.attr(\'type\') == \'checkbox\')
                            ?   ($this.is(\':checked\')) ? \'on\' : \'\'
                            :   $this.val() || \'\';
                value = fitValue(type, value);
                shortcode += $this.data(\'name\') + \'="\' + value + \'" \';
            });
            shortcode += \']\' + selectedContent + \'[/\' + shortcodeName + \'] \';

            /* Check for TinyMCE version */
            if (tmce_ver >= 4) {
                /* In TinyMCE 4, we must be use the execCommand */
                window.tinyMCE.execCommand(\'mceInsertContent\', false, shortcode);
            } else {
                /* In TinyMCE 3x and lower, we must be use the execInstanceCommand */
                 window.tinyMCE.execInstanceCommand(id, \'mceInsertContent\', false, shortcode);
            }
            tinyMCEPopup.editor.execCommand(\'mceRepaint\');
            tinyMCEPopup.close();
        }
    } catch (e) {
        console.error(e);
    }
    return;
}

结束

相关推荐

为什么dbDelta()不能捕获MysqlErrors?

据我所见,dbDelta() 用于抑制在其操作过程中发生的数据库错误。一般来说,情况似乎是这样,但New Relic仍在报告函数中的MysqlErrors。准确的错误消息格式如下:MysqlError: Table \'xxx.wp_yyy_posts\' doesn\'t exist 发件人dbDelta() 在里面/wp-admin/includes/upgrade.php, 我们有:// Fetch the table column structure from the database&