我目前正在使用PHP和jQuery开发图像浏览器。我设法创建了一个自定义按钮插件,可以在新窗口(而不是对话框)中打开图像浏览器:

CKEDITOR.plugins.add('imgbrowser',
{
    init: function(editor)
    {
        var pluginName = 'imgbrowser';
        editor.ui.addButton('Imgbrowser',
            {
                label: 'Image browser',
                command: pluginName,
                click: function (editor) { window.open('/publish/browser/index.php','Image Browser','width=900,height=600'); }
            });
    }
});


这里有人知道如何启用回调功能以及如何使用该回调功能,以便可以将所选图片添加到编辑器中吗?

最佳答案

好。答案是:

在父窗口中,我具有以下功能:

function InsertHTML(file_path)
        {
            // Get the editor instance that we want to interact with.
            var oEditor = CKEDITOR.instances.page_content;
            var value = file_path;

            // Check the active editing mode.
            if ( oEditor.mode == 'wysiwyg' )
            {
                // Insert the desired HTML.
                oEditor.insertHtml( '<img src="' + value + '" />' );
            }
            else
                alert( 'You must be on WYSIWYG mode!' );
        }


page_content是我的文本区域的ID。

在弹出窗口中,我具有以下功能:

function sendToParent(file_path) {
    window.opener.InsertHTML(file_path);
}


echo "<input type='button' value='Insert image' onclick='sendToParent(\"".$img_element."\")' />"

09-25 19:50