JavaScript different browser differences and compatibility methods

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.