(1)js按键事件兼容:function document.oncontextmenu() ie8可运行,谷歌改为function document.onkeydown()
(2)触发事件对象:IE浏览器支持window.event.srcElement,谷歌火狐支持window.event.target;兼容时做一下三目运算即可window.event.srcElement?window.event.srcElement:window.event.target
(3)style对象的cssText方法:ie8:obj.runtimeStyle.cssText ;谷歌:obj.runtimeStyle.cssText
(4)函数定义方式:function document.onclick() {}在谷歌浏览器内不支持,改为document.onclick = function (){}
(5)document.writeln:谷歌浏览器使用时需要添加name属性 document.writeln('<iframe id=endDateLayer name=endDateLayer frameborder=0 ></iframe>');
window.frames.endDateLayer.document.writeln(strFrame);
(6)document.all在IE、可以使用,谷歌浏览器不支持,所有以document.all.*方法获取对象的地方都改为document.getElementById或document.getElementsByName或document.getElementsByTagName。
(7)时间选择:对于简单的时间选择,可以将原有的弹框获取时间的方式改为WdatePicker, 例:<input type="text" onFocus="WdatePicker({lang:'zh-cn',dateFmt:'yyyy-MM-dd'})" class="Wdate"/>
(8)window.showModalDialog 兼容,在谷歌浏览器中可通过 window.open实现,
if (window.showModalDialog == undefined) {
ret = window.open(url + param, "", "width=345px,height=700px");
} else {
ret = window.showModalDialog(url + param, "", 'dialogWidth:345px;dialogHeight:700px;center:1');
return ret;
}
(9) 对于打开子窗口需要往父页面传值,可在父页面js打开子窗口时设置定时器检测子窗口是否关闭。
父页面设置定时器判断子窗口是否关闭:
winTimer=window.setInterval(function(){
if(ret.closed){
console.log(ret)
if(top.frames[0][1].returnValue !==undefined){
ret = top.frames[0][1].returnValue
return ret;
} else if (top.frames[0][0].returnValue !==undefined){
ret = top.frames[0][0].returnValue
return ret;
}
window.clearInterval(winTimer);
}
},500);
子窗口回值:
if (window.showModalDialog == undefined) {
parent.window.opener.returnValue = group_id + "$" + group_name ;
} else{
window.returnValue = group_id + "$" + group_name ;
}