---
title: "JavaScript常见兼容性问题"
author: "sunjing"
date: "2016-01-06T17:31:42Z"
tags: []
categories: ["Web前端"]
slug: "javascript"
draft: false
lastmod: "2016-12-07T09:15:00Z"
id: 2268983
url: "https://billben.iteye.com/blog/2268983"
---

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;

    ....

}

 

&lt;input type="button" onclick="click(event)" value="Hello Coco"&gt;

 

event.keyCode -&gt; 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](http://www.w3schools.com/jsref/default.asp)

[MSDN JavaScript Reference](https://msdn.microsoft.com/en-us/library/aa902517.aspx)

[MDN JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript)

[Why you should not use AngularJs](https://medium.com/@mnemon1ck/why-you-should-not-use-angularjs-1df5ddf6fc99#.874axk5od)