1.实例已存在报错
if(CKEDITOR.instances.contenttexts){
addCkeditor("contenttexts");
}else{
CKEDITOR.replace('contenttexts');
}
function addCkeditor(id){
var editor2 = CKEDITOR.instances[id];
if(editor2) editor2.destroy(true);//销毁编辑器 content2,然后新增一个
editor = CKEDITOR.replace(id);
}
2.图片上传
在 config.js 里面 加上:
config.image_previewText = ' ';
config.filebrowserUploadUrl = "admin/system/upload";
var pathName = window.document.location.pathname;
var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
config.filebrowserImageUploadUrl = projectName+'/system/upload.do'; //固定路径
Action地址固定
@Controller
@RequestMapping("/system")
public class UpLoadImgAction {
public static final Long maxFileSize = XX;
public static final Long maxVideoSize = XX;
@RequestMapping("/upload")
public void uploadImg(HttpServletRequest request,HttpServletResponse response,@RequestParam("upload") MultipartFile[] File) throws IOException{
String realpath = request.getSession().getServletContext()
.getRealPath("/");//服务存图片的文件夹地址
if (File != null && lFile.length > 0) {
if (!File[0].isEmpty()) {
long length = File[0].getSize();
if (length > maxFileSize) {
String jsht = "<script>alert('上传的图片过大(超700k),提交失败');</script>";
PublicSubfun.writehtml(jsht, response);
}
String[] type = File[0].getContentType().split("/");
File f = new File(realpath + "/" + System.currentTimeMillis()
+ "." + type[1]);
FileUtils.copyInputStreamToFile(picurlFile[0].getInputStream(),
f);
String url = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/服务存图片的文件夹地址/" + f.getName();
StringBuffer sb = new StringBuffer();
sb.append("<script type=\"text/javascript\">");
sb.append("window.parent.CKEDITOR.tools.callFunction("+ CKEditorFuncNum + ",'" +url + "','')");
sb.append("</script>");
PublicSubfun.writehtml(sb.toString(),response);}
}
}
}
</pre><pre>