jquery compatible Browser IE8 method

Source: Internet
Author: User

1. Preface

When doing front-end development, the company's specifications require customer-oriented compatibility to IE8, but in IE8 mode often find a variety of errors, such a method is undefined, does not support a property or object, etc., when using jquery, jquery is incompatible with IE8 from 2.0, with a minimum of support for IE9, so it is inherently compatible to introduce a lower jquery version.

2.IE8 does not support jquery version resolution

    • Load the corresponding version of jquery by judging the version of IE browser

Use statement <!--[if IE 8]> IE8 recognizable <![ endif]--> code as follows:

1 <script type= "Text/javascript" src= "<%=path%>/js/jquery-3.1.1.min.js" ></script>2  <!--[if IE 8]>3 <script type= "Text/javascript" src= "<%=path%>/js/ Jquery-1.9.1.min.js "></script>4<![ Endif]-->

  This way, when switching to IE8, the lower version of jquery overwrites the higher version of jquery. If you need to adjust the style of some elements under IE8, it's best to put the JS code at the bottom of the page (and notice if there are inline styles), otherwise the styles set for some dynamically loaded content may not take effect.

3.IE8 does not support foreach solutions

    • To add a custom foreach method to a browser that does not support foreach

The code is as follows:

1 if (typeof Array.prototype.forEach! = ' function ') {2     Array.prototype.forEach = function (callback) {3 for         (var i = 0; i < this.length; i++) {4             callback.apply (this, [this[i], I, this]); 5         }6     };7}

If the jquery plugin is introduced, you can place the code at the beginning of the plug-in's content so that the Foreach method under IE8 does not get an error.

jquery compatible Browser IE8 method

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.