在使用 UEditor 編輯器 時(shí)遇到了跨域的問題,導(dǎo)致無法發(fā)圖片,原因是由于 iframe 中的 src 跨域造成的,解決方法:
1.在 ueditor/dialogs/internal.js 加入 document.domain = '根域名';
2.在當(dāng)前頁面同樣指定根域名:
代碼如下:
<script type="text/javascript">
document.domain = "根域名";
</script>
這樣在 chrome、firefox 下沒有問題,但在 ie 下還需要簡單修改下 UEditor,在 editor.js 中找到:
this._setup( container.firstChild.contentWindow.document );
在它上邊加入下邊的代碼:
復(fù)制代碼 代碼如下:
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 跨域傳圖片的問題,希望對(duì)大家有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選