最近在开发项目中,需要获取到富文本编辑器内的图片上传信息,用来单独保存图片信息。
具体如下:
找到ueditor.all.js
找到simpleupload 方法
找到如下代码片段
function callback(){
try{
var link, json, loader,
body = (iframe.contentDocument || iframe.contentWindow.document).body,
result = body.innerText || body.textContent || '';
json = (new Function("return " + result))();
link = me.options.imageUrlPrefix + json.url;
if(json.state == 'SUCCESS' && json.url) {
loader = me.document.getElementById(loadingId);
loader.setAttribute('src', link);
loader.setAttribute('_src', link);
loader.setAttribute('title', json.title || '');
loader.setAttribute('alt', json.original || '');
loader.removeAttribute('id');
domUtils.removeClasses(loader, 'loadingclass');
me.fireEvent('simpleupload_customcomplete', containerBtn.id, link, json.title || '', json.original || '');
} else {
showErrorLoader && showErrorLoader(json.state);
}
}catch(er){
showErrorLoader && showErrorLoader(me.getLang('simpleupload.loadError'));
}
form.reset();
domUtils.un(iframe, 'load', callback);
}加入如下代码(上面片段内已加入)
me.fireEvent('simpleupload_customcomplete', containerBtn.id, link, json.title || '', json.original || '');业务页面内监听
var ue = UE.getEditor('company');
ue.addListener('simpleupload_customcomplete', function (types, id, link, title, alt) {
console.log(link);
//自定义逻辑代码
});