修正kindeditor带base标签页面图片显示的问题

问题详见:
http://www.kindsoft.net/view.php?bbsid=5&postid=2713
http://www.kindsoft.net/view.php?bbsid=4&postid=6332&cmtid=8839

原因:富文本编辑器的所见即所得功能是通过插入iframe实现的,如果iframe里面没有base标签,浏览器自然会选用当前页面的相对路径。

解决办法:往富文本编辑器的iframe插入当前页面的base标签路径。

Kindeditor版本:最新的4.1.7

打开需要用到的kineditor-all.js或者kindeditor.js,修改后自行压缩

找到 function _getBasePath()
在下面添加:
function _getPageBasePath() {
	var els = document.getElementsByTagName('base');
	for (var i = 0, len = els.length; i < len; i++) {
		var href = els[i].href;
		if (href) {
			return href;
		}
	}
	return '';
}
K.pageBasePath = _getPageBasePath();

再找到 function _getInitHtml(themesPath, bodyClass, cssPath, cssData)
在 '<head><meta charset="utf-8" /><title></title>', 下面新增一行
(K.pageBasePath === '' ? '' : '<base href="' + K.pageBasePath + '">'),


问题解决

猜你喜欢

转载自xiaoyaozjl.iteye.com/blog/1938405