1.4.2之后官方并沒有做功能的改動(dòng),1.4.2在word復(fù)制這塊沒有bug,其他版本會(huì)出現(xiàn)手動(dòng)無法轉(zhuǎn)存的情況
本文使用的后臺(tái)是Java。前端為Jsp(前端都一樣,后臺(tái)如果語言不通得自己做 Base64編碼解碼)
因?yàn)楣緲I(yè)務(wù)需要支持IE8 ,網(wǎng)上其實(shí)有很多富文本框,效果都很好。
例如www.wangEditor.com? 但試了一圈都不支持IE8 。
所以回到Ueditor,由于官方?jīng)]有維護(hù),新的neuditor 也不知道什么時(shí)候能支持word自動(dòng)轉(zhuǎn)存,只能自己想辦法。
如果沒有必要,不建議使用ueditor。我也是沒有辦法。
改動(dòng)過后的插件只適合IE8。
這里要說明的一點(diǎn)是百度官方的編輯器不支持word圖片批量轉(zhuǎn)存,粘貼word后需要手動(dòng)選擇圖片再進(jìn)行上傳一次操作。網(wǎng)上找到的大部分的示例都是這個(gè)操作。如果需要自動(dòng)批量上傳word圖片的話可以使用WordPaster這個(gè)控件。
1.IE設(shè)置
在受信任站點(diǎn)里添加信任網(wǎng)站。
這里本機(jī)測(cè)試使用的直接是?? http://localhost
因?yàn)樾枰x取客戶端的文件,所以需要設(shè)置允許訪問數(shù)據(jù)源。
ActiveXObject設(shè)置可以去網(wǎng)上參考,這里不列舉了。
前面的
到這里 IE 的準(zhǔn)備工作完成了。
修改ueditor.all.js關(guān)鍵代碼
14006行附近,如果是其他版本的ueditor,在功能正常的情況下,可以拷貝下面代碼。
var imgPath?= attrs.src;
var imgUrl?= attrs.src;
if?(navigator.appName?===?'Microsoft Internet Explorer')?{?//判斷是否是IE瀏覽器
????if?(navigator.userAgent.match(/Trident/i)?&& navigator.userAgent.match(/MSIE 8.0/i))?{?//判斷瀏覽器內(nèi)核是否為Trident內(nèi)核IE8.0
??????? var realPath?= imgPath.substring(8, imgPath.length);
??????? var filename?= imgPath.substring(imgPath.lastIndexOf('/')?+ 1, imgPath.length);
??????? var result?= UploadForIE.saveAttachment(filename, realPath);
????????if?(result)?{
??????????? var json?= eval('('?+ result?+?')');
??????????? imgUrl?= json.url;
????????}
????}
}
img.setAttr({
??? width: attrs.width,
??? height: attrs.height,
??? alt: attrs.alt,
??? word_img: attrs.src,
??? src: imgUrl,
????'style':?'background:url('?+?(flag?? opt.themePath?+ opt.theme?+?'/images/word.gif': opt.langPath?+ opt.lang?+?'/images/localimage.png')?+?') no-repeat center center;border:1px solid #ddd'
})
uploadForIE.js。
var UploadForIE?=?{
????//?保存到xml附件,并且通過ajax 上傳
??? saveAttachment:?function(upload_filename,?localFilePath)?{
????????//后臺(tái)接受圖片保存的方法。
??????? var upload_target_url?=?"uploadImg";
??????? var strTempFile?=?localFilePath;
????????//?創(chuàng)建XML對(duì)象,組合XML文檔數(shù)據(jù)
??????? var xml_dom?=?UploadForIE.createDocument();
??????? xml_dom.loadXML('<?xml version="1.0" encoding="GBK" ?> <root/>');
????????//?創(chuàng)建ADODB.Stream對(duì)象
??????? var ado_stream?=?new?ActiveXObject("adodb.stream");
????????//?設(shè)置流數(shù)據(jù)類型為二進(jìn)制類型
??????? ado_stream.Type?=?1;?// adTypeBinary
????????//?打開ADODB.Stream對(duì)象
??????? ado_stream.Open();
????????//?將本地文件裝載到ADODB.Stream對(duì)象中
??????? ado_stream.LoadFromFile(strTempFile);
????????//?獲取文件大?。ㄒ宰止?jié)為單位)
??????? var byte_size?=?ado_stream.Size;
????????//?設(shè)置數(shù)據(jù)傳輸單元大小為1KB
??????? var byte_unit?=?1024;
????????//?獲取文件分割數(shù)據(jù)單元的數(shù)量
??????? var read_count?=?parseInt((byte_size?/?byte_unit).toString())?+?parseInt(((byte_size?%?byte_unit)?==?0)???0?:?1);
????????//?創(chuàng)建XML元素節(jié)點(diǎn),保存上傳文件名稱文章來源:http://www.zghlxwxcb.cn/news/detail-765656.html
??????? var node?&#文章來源地址http://www.zghlxwxcb.cn/news/detail-765656.html
到了這里,關(guān)于百度ueditor如何能實(shí)現(xiàn)直接粘貼把圖片上傳到服務(wù)器中的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!