Original link: http://caibaojian.com/js-ie-different-from-firefox.html
JavaScript compatibility is to solve different browser differences, understand the differences can help you solve problems faster, improve the quality of the use of code, write better JavaScript code.
1.window.event
Represents the current time object, IE has this object, FF No, FF passes the event object to the event handler function
2. Get the event source
IE uses srcelement to get the event source, while FF gets the event source with target
The above two compatibility is usually written like this:
var evt = e| | Event;var el = Evt.srctarget | | Evt.srcelement;
3. Adding and Removing events
4. Get custom properties for tags
IE:div1.value or div1[' value ']
FF: Available Div1.getattribute ("value")
5.document.getelemntbyname () and Document.all[name]
IE can not,
FF can
Properties of the 6.input.type
7.IE supports innertext, outerhtml
FF: Support Textcontent
8. Location of the window
IE, Chrome, Safari: Support for using Window.screenleft and Window.screentop
IE8 above, Chrome, Safari, Firefox: support for using Window.screenx and Window.screeny
Compatible code can use the following code:
var leftx = typeof Window.screenleft = = ' number '? Window.screenleft:window.screenx;ver topy = typeof Window.screentop = = ' number '? Window.screenTop:window.screenY;
9. Size of the window
Firefox, Chrome, IE9 and Safari:window.innerWidth and Window.innerheight
IE series: Document.body.clientWidth and Document.body.clientHeight
Not IE6:document.documentElement.clientWidth and Document.documentElement.clientHeight.
Compatible code can write like this
code from Http://caibaojian.com/js-ie-different-from-firefox.htmlvar width = window.innerwidth;var height = Window.innerheight;if (typeof width! = ' number ') {if (Document.compatmode = = ' Css1compat ') {width = Document.documentelement.clientwidth;height = Document.docuementElement.clientHeight;} Else{width = Document.body.clientwidth;height = Document.body.clientHeight;}
The above content reference network, because I learn JavaScript knowledge is relatively small, temporarily do not know, so in advance to learn, so that later encountered can be quickly identified. Updates will continue to be added later in this article.
JavaScript different browser differences and compatibility methods