Browser compatibility: Javascript

Source: Internet
Author: User

1.event

IE9 below does not support direct acquisition of event objects, so write compatibility is required:

var event = event?event:window.event;

IE8 below are not supported for Event.target, but can be compatible with event.srcelement:

var eventtarget = Event.srcelement?event.srcelement:event.target;

2.document.getelementsbyclassname ("...")

IE8 below is not supported, there is no workaround; can only be done for the current code hack

3.new Date (str) format error

If Str is not a string such as the standard Time format "2014/12/9", the new date will fail and return an error result;

The invalid Date is returned under Chrome, and Nan is returned under IE;

When dealing with error results, remember to take Nan

4.getYear Get Year

In IE, get the normal 2014,2013 value, and in Chrome and other browsers get 114,113, less than the normal year 1900; Get full year should use the getFullYear () function, in each browser to get 2014, 2013 normal year values

5.stopPropagation Block bubbling

IE9 do not support the use of the Event.stoppropagation () function, you should use event.cancelbubble = true;

var e = event?event:window.event;
if (e.stoppropagation) {
E.stoppropagation ();
}
else{
E.cancelbubble = true;
}

---Encounter some more, it is time to take note of the browser compatibility and solutions to the knowledge point-----

Browser compatibility: Javascript

Related Article

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.