UEditor 编辑器跨域上传解决方法

 更新时间:2013年06月12日 12:46:19   作者:  
在使用 UEditor 编辑器 时遇到了跨域的问题,导致无法发图片,原因是由于 iframe 中的 src 跨域造成的
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud

(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

解决的方法:

1.在 ueditor\dialogs\internal.js 加入 document.domain = '根域名';

2.在当前页面同样指定根域名:

复制代码 代码如下:

<script type="text/javascript">
    document.domain = "根域名";
</script>

这样在 chrome、firefox 下没有问题,但在 ie 下还需要简单修改下 UEditor,在 editor.js 中找到:

this._setup( container.firstChild.contentWindow.document );

在它上边加入下边的代码:

复制代码 代码如下:

if (ie) {
    document.getElementById('baidu_editor_' + this.uid).src = "javascript:(function(){document.open();document.domain='"+document.domain+"';document.close();})()";
}

接下来找到:

me.document = doc;

在它下边加入:

me.document.domain='根域名';

到这里就解决了 UEditor 跨域传图片的问题,希望对大家有所帮助。

作者:东奎 

相关文章

最新评论

?


http://www.vxiaotou.com