像许多其他应用一样,由于TinyMCE的图片插件的局限性,我决定采取一种创建与我自己网站的上传系统绑定的方式的方法。
我已经完成了部分工作,并拉出了一个专为该目的设计的单独页面。但是,现在我想从此页面上的选择图像中返回内容。那有可能还是我死胡同?
tinymce.PluginManager.add('imageLoader', function(editor, url) {
// Adds a menu item to the tools menu
editor.addButton('imageLoader', {
icon: 'mce-ico mce-i-link',
image: 'Photos.png',
onclick: function() {
// Open window
editor.windowManager.open({
title: 'Image Loader',
url: 'load_images',
width: 500,
height: 400,
onsubmit: function(e) {
// Insert content when the window form is submitted
editor.insertContent('Image To Insert');
}
});
}
});
return {
getMetadata: function () {
return {
name: "Image Loader"
};
}
};
});
最佳答案
我找到了答案,尽管这可能不是最优雅的解决方案。
我选择的图像将传递到自定义页面中的隐藏文本输入中。从那里开始,在提交或关闭TinyMCE 4框架时,我使用以下代码段:
let getVal = $('[role="application"]').find('iframe')[1].contentWindow.document.getElementById("imgHolder").value;
为了:
它首先找到iFrame。由于外部页面和编辑器本身都使用iFrame,因此通常将其称为“第二” iFrame-不幸的是,它没有ID。
“ contentWindow.document.getElementByID”获取隐藏的输入,在我的例子中为“ imgHolder”
在这里,您可以使用.value正常获取内容,并将其插入TinyMCE编辑器。
我希望这可以帮助其他人指明正确的方向,尤其是知道TinyMCE 4的需求量很大。此外,我希望这也可以变得更加优雅。