---
title: "简单快捷地在ckeditor加上图片上传功能  "
author: "sanr_"
date: "2013-06-08T22:56:25Z"
tags: []
categories: ["Web前端"]
slug: "ckeditor"
draft: false
lastmod: "2013-06-08T22:56:25Z"
id: 1884649
url: "https://gushan.iteye.com/blog/1884649"
---

ckeditor非常好用，但它的图片/文件上传使用了ckfinder，虽然功能非常强大，但集成起来还是比较麻烦，而且根据应用还需要改造。如果自己的应用已经有图片/文件上传模块，能否直接拿过来用呢？答案是肯定的，而且非常简单，就是在图片链接输入框的右边加个按钮，点击事件链接到已有的上传模块，上传后把图片的url传递给左边的输入框即可。步骤如下：  
  打开plugins\\image\\dialogs\\image.js，在链接输入框代码结尾也就是m.lang.image.urlMissing)},后面加上这些代码：  
{type:'button',id:'myUpload',align:'center',label:'新上传',onClick:function(){var retFile =  
showModalDialog("/common/uploadImage.jsp", "", "dialogHeight:20;dialogWidth:29;"); if(retFile !=  
null){this.getDialog().setValueOf('info','txtUrl',retFile);}}},  
  /common/uploadImage.jsp是应用已经有的上传模块链接，上传成功后通过模式对话框的returnValue返回图片链接，比如在上传成功页面加上如下js函数，点击确定时调用。 function Done() {  
  window.returnValue = imgPath; //上传后的图片链接   window.close(); }