针对ayer弹出层在IE上关闭导致浏览器崩溃的问题:
导致原因:
查看src源码,layer.close关闭总方法中有这么一行:
layer.close = function(index){ var layero = $('#'+ doms[0] + index), type = layero.attr('type'), closeAnim = 'layer-anim-close'; if(!layero[0]) return; var WRAP = 'layui-layer-wrap', remove = function(){ if(type === ready.type[1] && layero.attr('conType') === 'object'){ layero.children(':not(.'+ doms[5] +')').remove(); var wrap = layero.find('.'+WRAP); for(var i = 0; i < 2; i++){ wrap.unwrap(); } wrap.css('display', wrap.data('display')).removeClass(WRAP); } else { //低版本IE 回收 iframe if(type === ready.type[2]){ try { var iframe = $('#'+doms[4]+index)[0]; iframe.contentWindow.document.write(''); iframe.contentWindow.close(); layero.find('.'+doms[5])[0].removeChild(iframe); } catch(e){} } //整个layer.js上下文只有这一个“innHTML”的操作!!!!!嫌啰嗦的直接搜索吧!!! layero[0].innerHTML = ''; layero.remove(); } typeof ready.end[index] === 'function' && ready.end[index](); delete ready.end[index]; }; if(layero.data('isOutAnim')){ layero.addClass(closeAnim); } $('#layui-layer-moves, #layui-layer-shade' + index).remove(); layer.ie == 6 && ready.reselect(); ready.rescollbar(index); if(layero.attr('minLeft')){ ready.minIndex--; ready.minLeft.push(layero.attr('minLeft')); } if((layer.ie && layer.ie < 10) || !layero.data('isOutAnim')){ remove() } else { setTimeout(function(){ remove(); }, 200); } };
为什么下面一行代码都layero.remove()了,还需要上面的操作,真实情况是IE9-并不支持对属性“innerHTML”进行操作(文献)!!!
解决方案:
//layero[0].innerHTML = '';
这具体在干什么,我就不明说了,哈哈!