Javascript browser compatibility issues

Source: Internet
Author: User
1. Window. Event

Symptom:

Document. Body. onclick = function (EV) {If (EV) console. Log (1); else console. Log (2 );}

IE8 or earlier does not support this method.

Document. Body. onclick = function () {If (window. Event) console. Log (1); else console. Log (2 );}

FF does not support this method.

Ie9 and chrome support both window. Event and Ev.

 

Solution:

 

Document. Body. onclick = function (EV ){

Ev = Ev? Ev: window. event;

If (EV) console. Log (1); elseconsole. Log (2 );

}

2. innertext and textcontent

Symptom:

Innertext and textcontext

Ie9 and chrome support both

IE8 supports innertext

FF supports textcontent

 

Solution:

 

TEXT = E. textcontent | E. innertext

 

3. innerhtml

Symptom:

In ie, the following statement is used: Table. innerhtml = content; when the HTML content of the table is dynamically modified, an unknown running error occurs ". Cause of error: in IE browser, the innerhtml attribute of table is read-only and cannot be changed. Similarly, thead, tfoot, and TR (the only exception is TD ). (Firefox can be used normally)

Solution:

1. Use the object model or DOM method of the table to dynamically modify the table, such as insertrow, insertcell, createtfoot, createthead, or apendchild.

2. Locate the table's TD and use TD's innerhtml for dynamic operations.

4. Li and Span

Symptom:

<Ul> <spanid = "test"> <li> FDFD </LI> </span> </ul>

Document. getelementbyid ('test'). innerhtml output in ie9: <li> FDFD

Chrome and FF are normal.

Solution:

You can change span to Div.

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.