首先,修改对CKEditor引入的那部分javascript,代码如下:
01 CKEDITOR.replace('content',addUploadButton(this));
02 function addUploadButton(editor){
03 CKEDITOR.on('dialogDefinition', function( ev ){
04 var dialogName = ev.data.name;
05 var dialogDefinition = ev.data.definition;
06 if ( dialogName == 'image' ){
07 var infoTab = dialogDefinition.getContents( 'info' );
08 infoTab.add({
09 type : 'button',
10 id : 'upload_image',
11 align : 'center',
12 label : '上传图片',
13 onClick : function( evt ){
14 var thisDialog = this.getDialog();
15 var txtUrlObj = thisDialog.getContentElement('info', 'txtUrl');
16 var txtUrlId = txtUrlObj.getInputElement().$.id;
17 addUploadImage(txtUrlId);
18 }
19 }, 'browse'); //place front of the browser button
20 }
21 });
22 }
23 function addUploadImage(theURLElementId){
24 var uploadUrl = "myCkeditor/uploadImage.action"; //这是我自己的处理文件/图片上传的页面URL
25 var imgUrl = window.showModalDialog(uploadUrl,null,"dialogWidth:360px;dialogHeight:120px;help:no;status:no");
26 var urlObj = document.getElementById(theURLElementId);
27 urlObj.value = imgUrl;
28 //alert(imgUrl);
29 urlObj.fireEvent("onchange"); //触发url文本框的onchange事件,以便预览图片
30 }