使用WindowManager for TinyMCE我打开一个窗口,然后写回原始HTML。但它截断我的图像链接。奇怪的是它不会对锚标签这么做。只是图片标签。
我有这段代码
html = '<a title="'+ $('#title').val() +'" href="'+ $('#url').val() +'"><img src="'+ $('#imgURL').val() +'" /></a>';
var parentEditor = parent.tinyMCE.activeEditor;
parentEditor.execCommand('mceInsertRawHTML', false, html);
parentEditor.windowManager.close();
它将html插入到活动的编辑器中。当我将 html 记录到控制台时,我得到了
<a title="Click Action" href="yahoo.com"><img src="http://marketingedu.mychm.co/images/buttons/c2a-button4.png" /></a>
但是当我在tinyMCE编辑器中查看源代码时,它将图像SRC属性更改为
../../images/buttons/c2a-button4.png
这是我对TinyMCE编辑器的整个javascript初始化
tinymce.init({
selector: ".editor",
setup: function(ed) {
ed.on('change', function(e) {
tinyMCE.triggerSave();
$('form').trigger('checkform.areYouSure');
});
ed.on('init', function(e) {
autoresize_max_height: 500
});
ed.addButton('defaultbtn', {
title: 'Insert Button',
icon: 'fa fa-plus-square',
onclick: function() {
// Open window
ed.windowManager.open({
title: 'Button Selector',
url: "<?=$this->url('/webinar/custombuttons') ?>",
width: 800,
height: 600
});
}
});
},
plugins: [
"advlist autolink link responsivefilemanager lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"save table contextmenu directionality template paste textcolor colorpicker responsivefilemanager autoresize"
],
toolbar: "undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright | bullist numlist | outdent indent | table | link responsivefilemanager defaultbtn",
image_advtab: true ,
external_filemanager_path:"/filemanager/",
filemanager_title:"Filemanager" ,
external_plugins: { "filemanager" : "/filemanager/plugin.min.js"},
});
答案 0 :(得分:7)
改变这个:
var parentEditor = parent.tinyMCE.activeEditor;
parentEditor.execCommand('mceInsertRawHTML', false, html);
To This:
tinymce.activeEditor.setContent(html, {format: 'raw'});
以下是有关如何以各种方式设置内容的参考link。
希望这有帮助。