最近在开发项目中,需要获取到富文本编辑器内的图片上传信息,用来单独保存图片信息。看了官方文档,无解。百度各种文章,无解。最后百度了许久才解决解决了问题。
具体如下:
1、找到ueditor.all.js
2、找到simpleupload 方法
3、找到如下代码片段
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 || '');
4、业务页面内监听
var ue = UE.getEditor('company'); ue.addListener('simpleupload_customcomplete', function (types, id, link, title, alt) { console.log(link); //等等等一堆代码 });