百度编辑器ueditor爬坑记-------ie下初始化报错

ueditor.all.js中有一个方法如下:


        /**
         * 渲染编辑器的DOM到指定容器
         * @method render
         * @param { Element } containerDom 直接指定容器对象
         * @remind 执行该方法,会触发ready事件
         * @warning 必须且只能调用一次
         */
        render: function (container) {
            var me = this,
                options = me.options,
                getStyleValue=function(attr){
                    return parseInt(domUtils.getComputedStyle(container,attr));
                };
            if (utils.isString(container)) {
                container = document.getElementById(container);
            }
            
            //.......

            //.......

       }

该方法是初始化编辑器的,但是。ie下这个方法中有一段就是这个方法中我打省略号的地方的这段,这段报错。具体不分析了,直接上解决办法。将该方法直接替换为如下即可:


        /**
         * 渲染编辑器的DOM到指定容器
         * @method render
         * @param { Element } containerDom 直接指定容器对象
         * @remind 执行该方法,会触发ready事件
         * @warning 必须且只能调用一次
         */
        render: function (container) {
            var me = this,
                options = me.options,
                getStyleValue=function(attr){
                    return parseInt(domUtils.getComputedStyle(container,attr));
                };
            if (utils.isString(container)) {
                container = document.getElementById(container);
            }
			if ( container ) {
				//获取默认语种
				var fontfamily = "宋体",isbreak="word-break:break-all";
				var useBodyAsViewport = ie && browser.version < 9,
						html = ( ie && browser.version < 9 ? '' : '<!DOCTYPE html>') +
								'<html xmlns=\'http://www.w3.org/1999/xhtml\'' + (!useBodyAsViewport ? ' class=\'view\'' : '') + '><head>' +
								( options.iframeCssUrl ? '<link rel=\'stylesheet\' type=\'text/css\' href=\'' + utils.unhtml( options.iframeCssUrl ) + '\'/>' : '' ) +
								 '<link id="thecss" rel="stylesheet" type="text/css" href="about:blank">'+
								'<style type=\'text/css\'>' +
							//设置四周的留边
								'.view{padding:0;'+isbreak+';cursor:text;height:100%;}\n' +
							//设置默认字体和字号
							//font-family不能呢随便改,在safari下fillchar会有解析问题
								//'body{margin:8px;font-family:sans-serif;font-size:16px;}' +
								'body{margin-left:0px;margin-right:0px;margin-bottom:0px;margin-top:0px;font-family:"'+fontfamily+'";font-size:14px;}' +
							//设置段落间距
								'p{margin:5px 0;}'
								+ ( options.initialStyle || '' ) +
								'</style></head><body style="height:100%;" ' + (useBodyAsViewport ? ' class="view"' : '')  + '></body>';
				if ( options.customDomain && document.domain != location.hostname ) {
					html += '<script>window.parent.UE.instants[\'ueditorInstant' + me.uid + '\']._setup(document);</script></html>';
					container.appendChild( domUtils.createElement( document, 'iframe', {
						id:'baidu_editor_' + me.uid,
						width:"100%",
						height:"100%",
						frameborder:"0",
						src:'javascript:void(function(){document.open();document.domain="' + document.domain + '";' +
								'document.write("' + html + '");document.close();}())'
					} ) );
				} else {
					  container.innerHTML = '<iframe name="ueditor_subcontent" id="' + 'baidu_editor_' + this.uid + '"' + ' style="width:100%;height:100%" class="mainiframe" scrolling="yes" frameborder="0"></iframe>';
					var doc = container.firstChild.contentWindow.document;
					//去掉了原来的判断!browser.webkit,因为会导致onload注册的事件不触发
					doc.open();
					doc.write( html + '</html>' );
					doc.close();
					me._setup( doc );
				}
				container.style.overflow = 'hidden';
				//注册编辑区切换监听
				//addEditorListener(container.firstChild.contentWindow.document);
				setTimeout(function(){
					if( /%$/.test(options.initialFrameWidth)){
						options.minFrameWidth = options.initialFrameWidth = container.offsetWidth;
						//如果这里给定宽度,会导致ie在拖动窗口大小时,编辑区域不随着变化
			//                        container.style.width = options.initialFrameWidth + 'px';
					}
					if(/%$/.test(options.initialFrameHeight)){
						options.minFrameHeight = options.initialFrameHeight = container.offsetHeight;
						container.style.height = options.initialFrameHeight + 'px';
					}
				})
			}

        },

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值