ueditor百度编辑器上传PDF并显示
作者:野牛程序员:2023-12-05 10:05:30其他阅读 3001
ueditor.all.js
在commands 项中添加:
if(title.indexOf("pdf")>0){
html +='<iframe style="width: 100%;height: 600px;border: 0px;overflow: hidden" width="100%" height="500px" src="'+item.url+'"></iframe>';
}else{
html += '<p style="line-height: 16px;">' + '<img style="vertical-align: middle; margin-right: 2px;" src="'+ icon + '" _src="' + icon + '" />' + '<a style="font-size:12px; color:#0066cc;" href="' + item.url +'" title="' + title + '">' + title + '</a>' + '</p>';
}添加后变成
commands:{
'insertfile': {
execCommand: function (command, filelist){
filelist = utils.isArray(filelist) ? filelist : [filelist];
var i, item, icon, title,
html = '',
URL = me.getOpt('UEDITOR_HOME_URL'),
iconDir = URL + (URL.substr(URL.length - 1) == '/' ? '':'/') + 'dialogs/attachment/fileTypeImages/';
for (i = 0; i < filelist.length; i++) {
item = filelist[i];
icon = iconDir + getFileIcon(item.url);
title = item.title || item.url.substr(item.url.lastIndexOf('/') + 1);
if(title.indexOf("pdf")>0){
html +='<iframe style="width: 100%;height: 600px;border: 0px;overflow: hidden" width="100%" height="500px" src="'+item.url+'"></iframe>';
}else{
html += '<p style="line-height: 16px;">' + '<img style="vertical-align: middle; margin-right: 2px;" src="'+ icon + '" _src="' + icon + '" />' + '<a style="font-size:12px; color:#0066cc;" href="' + item.url +'" title="' + title + '">' + title + '</a>' + '</p>';
}
//把下面代码屏蔽
// html += '<p style="line-height: 16px;">' +
// '<img style="vertical-align: middle; margin-right: 2px;" src="'+ icon + '" _src="' + icon + '" />' +
// '<a style="font-size:12px; color:#0066cc;" href="' + item.url +'" title="' + title + '">' + title + '</a>' +
// '</p>';
}
me.execCommand('insertHtml', html);
}
}
}ueditor.config.js
在whitList: 项中添加
iframe: ['src', 'width', 'height', 'style'],
添加后的效果
,whitList: {
iframe: ['src', 'width', 'height', 'style'],
a: ['target', 'href', 'title', 'class', 'style'],
abbr: ['title', 'class', 'style'],
address: ['class', 'style'],
area: ['shape', 'coords', 'href', 'alt'],
article: [],
aside: [],
audio: ['autoplay', 'controls', 'loop', 'preload', 'src', 'class', 'style'],
b: ['class', 'style'],
bdi: ['dir'],
bdo: ['dir'],
big: [],
blockquote: ['cite', 'class', 'style'],
br: [],
caption: ['class', 'style'],
center: [],
cite: [],
code: ['class', 'style'],
col: ['align', 'valign', 'span', 'width', 'class', 'style'],
colgroup: ['align', 'valign', 'span', 'width', 'class', 'style'],
dd: ['class', 'style'],
del: ['datetime'],
details: ['open'],
div: ['class', 'style'],
dl: ['class', 'style'],
dt: ['class', 'style'],
em: ['class', 'style'],
font: ['color', 'size', 'face'],
footer: [],
h1: ['class', 'style'],
h2: ['class', 'style'],
h3: ['class', 'style'],
h4: ['class', 'style'],
h5: ['class', 'style'],
h6: ['class', 'style'],
header: [],
hr: [],
i: ['class', 'style'],
img: ['src', 'alt', 'title', 'width', 'height', 'id', '_src', 'loadingclass', 'class', 'data-latex'],
ins: ['datetime'],
li: ['class', 'style'],
mark: [],
nav: [],
ol: ['class', 'style'],
p: ['class', 'style'],
pre: ['class', 'style'],
s: [],
section:[],
small: [],
span: ['class', 'style'],
sub: ['class', 'style'],
sup: ['class', 'style'],
strong: ['class', 'style'],
table: ['width', 'border', 'align', 'valign', 'class', 'style'],
tbody: ['align', 'valign', 'class', 'style'],
td: ['width', 'rowspan', 'colspan', 'align', 'valign', 'class', 'style'],
tfoot: ['align', 'valign', 'class', 'style'],
th: ['width', 'rowspan', 'colspan', 'align', 'valign', 'class', 'style'],
thead: ['align', 'valign', 'class', 'style'],
tr: ['rowspan', 'align', 'valign', 'class', 'style'],
tt: [],
u: [],
ul: ['class', 'style'],
video: ['autoplay', 'controls', 'loop', 'preload', 'src', 'height', 'width', 'class', 'style']
}野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892

- 上一篇:小学二年级语文上期中检测卷
- 下一篇:c语言计算a+|b|
