解决ueditor 上传图片在IE中的兼容问题

修正ueditor不兼容IE的单图片BUG

找到源码中 simpleupload 模块 ,搜索 initUploadBtn,修改其中的一段代码为如下所示

            domUtils.on(input, 'change', function(){
                function showErrorLoader(title){
                    if(loadingId) {
                        var loader = me.document.getElementById(loadingId);
                        loader && domUtils.remove(loader);
                        me.fireEvent('showmessage', {
                            'id': loadingId,
                            'content': title,
                            'type': 'error',
                            'timeout': 4000
                        });
                    }
                }
            	function createXMLHttpRequest() {
            		if(window.XMLHttpRequest){
            			return new XMLHttpRequest();
            		} else {
            			var names=["msxml","msxml2","msxml3","Microsoft"];
            			for(var i=0;i');

                /* 判断后端配置是否没有加载成功 */
                if (!me.getOpt('imageActionName')) {
                    errorHandler(me.getLang('autoupload.errorLoadConfig'));
                    return;
                }
                // 判断文件格式是否错误
                var filename = input.value,
                    fileext = filename ? filename.substr(filename.lastIndexOf('.')):'';
                if (!fileext || (allowFiles && (allowFiles.join('') + '.').indexOf(fileext.toLowerCase() + '.') == -1)) {
                    showErrorLoader(me.getLang('simpleupload.exceedTypeError'));
                    return;
                }
                
        		var formData = new FormData();
        		var file=input.files[0];
        		formData.append(me.options.imageFieldName, file);
        		
        		var xhr = createXMLHttpRequest();
        		xhr.open('POST', imageActionUrl + (imageActionUrl.indexOf('?') == -1 ? '?':'&') + params, true);
        		xhr.onreadystatechange = function(){
        			
        			  //响应完成且响应正常  
        		    if (xhr.readyState == 4)  
        		    {  
        		        if (xhr.status == 200)  
        		        {  
        		        	json = (new Function("return " + xhr.responseText))();
                            link = me.options.imageUrlPrefix + json.url;
                            if(json.state == 'SUCCESS' && json.url) {
                                loader = me.document.getElementById(loadingId);
                                loader.setAttribute('src', link);
                                loader.setAttribute('_src', link);
                                loader.setAttribute('title', json.title || '');
                                loader.setAttribute('alt', json.original || '');
                                loader.removeAttribute('id');
                                domUtils.removeClasses(loader, 'loadingclass');
                            } else {
                                showErrorLoader && showErrorLoader(json.state);
                            }
                            
        		        }  
        		        else  
        		        {  		           
                            showErrorLoader && showErrorLoader(me.getLang('simpleupload.loadError'));
        		        }  
        		        form.reset();
        		    }  
        			
        		};

        		xhr.send(formData);
            	
            	
            });

 

转载于:https://my.oschina.net/u/3071114/blog/994801

你可能感兴趣的:(解决ueditor 上传图片在IE中的兼容问题)