JavaScript常见兼容性问题

1. window.frames

Returns the window itself, which is an array-like object, listing the direct sub-frames of the current window.

window.frames[0] is the same thing as document.getElementsByTagName("iframe")[0].contentWindow

 2. window.event

在老版本IE或兼容模式中支持,可将方法的第一个参数设为event,如

function click(event) {

    var e = event || window.event;

    var element = e.target || e.srcElement;

    ....

}

<input type="button" onclick="click(event)" value="Hello Coco">

event.keyCode -> event.key

3. document.getElementById()

在IE兼容模式中,如根据id找不到元素,将根据name查找。

4. window.showModalDialog

IE和firefox支持window.showModalDialog,chrome 37后不支持,请用window.open代替:

window.open("http://www.w3schools.com", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");

W3 JavaScript Reference

MSDN JavaScript Reference

MDN JavaScript

Why you should not use AngularJs

猜你喜欢

转载自billben.iteye.com/blog/2268983