kindeditor的跨域上传文件
2015-07-15 12:26
267 查看
目前只支持在同一根域下的支持,如从(a.test.com上传到img.test.com)网上例子很多,但是太乱了,其实很简单,几行代码就解决了,下面请看:首先,去官网下载最新的kindeditor,然后部署到img.test.com上,保证可以通过img.test.com/jsp/upload_json.jsp 访问到kindeditor的接口然后,修改img服务器上的upload_json.jsp,在顶部添加
/** * KindEditor JSP * * 本JSP程序是演示程序,建议不要直接在实际项目中使用。 * 如果您确定直接使用本程序,使用之前请仔细确认相关安全设置。 * */
//文件保存目录路径 String savePath = pageContext.getServletContext().getRealPath("/") + "attached/"; //文件保存目录URL //String uri = request.getContextPath() + "/attached/"; String saveUrl = "http://img.test.com/attached/";接着在底下out.println(obj.toJSONString());的上面添加
out.println("<script type='text/javascript'>document.domain = 'ezhensuo.com'</script>");这样,服务器端的配置就ok了然后,在本地部署kindedior,jsp上初始化kindeditor
<script type="text/javascript"> document.domain = "test.com"; KindEditor.ready(function(K) { var editor1 = K.create('textarea[name="contentText"]', { afterBlur: function () { this.sync(); }, cssPath : 'http://file.ezhensuo.com/plugins/code/prettify.css', uploadJson : 'http://file.ezhensuo.com/jsp/upload_json.jsp', fileManagerJson : 'http://file.ezhensuo.com/jsp/file_manager_json.jsp', allowFileManager : true, allowImageRemote:false, items:[ 'source', '|', 'undo', 'redo', '|', 'preview', 'cut', 'copy', 'paste', 'plainpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'table', 'hr', 'emoticons', 'pagebreak', 'anchor', 'link', 'unlink', '|' ], afterCreate : function() { var self = this; K.ctrl(document, 13, function() { self.sync(); document.forms['example'].submit(); }); K.ctrl(self.edit.doc, 13, function() { self.sync(); document.forms['example'].submit(); }); } }); prettyPrint(); });
</script>这样,跨域就完成了,其实最主要的就是document.domain = "test.com";//根域因为,编辑器原理大多是Form提交到iframe,然后本地通过js调用返回的url,但是你不写domain的话就会报域名头不一致无法跨域的问题,现在服务器端返回一个script domain就可以跨域了哈
相关文章推荐
- Basic Calculator
- Swift 中的函数
- java中遍历MAP的几种方法
- 安全系列------web环境搭建组合
- Mybatis绑定错误的原因
- tarjan题目(2)爱在心中
- lua-md5 for lua5.3
- 求水仙花数
- 基于NodeJS的前后端分离的思考与实践(六)Nginx + Node.js + Java 的软件栈部署实践
- Genymotion模拟器离线安装 无需登陆
- 2013下半年软件评测师真题考试分析-1
- java List 排序 Collections.sort() 对 List 排序
- Swift 集合类型(Collection Type) 之 数组(array)(官方文档翻译及总结)
- Android 利用Theme自定义Activity间的切换动画
- 求1-100之间的所有素数
- Android移动view动画问题
- ajax+php控制所有后台函数调用
- 安全系列------动态网站与静态网站的区别
- 用redis实现社交产品中计数器
- 跳转webview白屏(黑屏)问题解决