如果使用的是百度编辑器,请使用135为百度编辑器开发的插件,点击可进入。
1在页面中调用135编辑器
通过window.open打开135编辑器,需要传入一个callback参数,为回调地址的url。
实现一个编辑器内容使用的js方法,供编辑完成后调用。
function show135Editor(){
var url = 'http://www.135editor.com/beautify_editor?callback=xxxx';
window.open(url,'new_window','dialogHeight:750px; dialogWidth:1000px;help:No;resizable:No;status:No;scroll:Yes');
}
function get_135editor_content($html) {
ckeditor.setData($html); // ueditor.setContent($html);
}
2设置回调地址的功能
由于调用135编辑器会有跨域的问题,在135地址完成编辑时,会将结果提交到回调地址,通过回调地址调用最上层的内容使用函数。设置内容完成后,输出iframe调用135编辑器的关闭页面,关闭打开的135窗口。
注意:需要设置内容输出编码为utf-8格式
<script>
var onMessage = function(e){
parent.window.opener.get_135editor_content(e.data);
document.write("<iframe style=\"display:none;\" src=\"http://www.135editor.com/pages/closeWindow.html\"></iframe>");
}
if (window.addEventListener) { // all browsers except IE before version 9
window.addEventListener("message", onMessage, false);
} else {
if (window.attachEvent) { // IE before version 9
window.attachEvent("onmessage", onMessage);
}
}
</script>
3使用体验
流程体验:
访问地址 http://www.135editor.com/feed_backs/add
点击使用135编辑器编辑内容的按钮,
输入编辑内容完成编辑后,点击“完成编辑”按钮
内容设置到了输入框中。