Test the compatibility of IE browser with JavaScript AngularJS and angularjs

Source: Internet
Author: User

Test the compatibility of IE browser with JavaScript AngularJS and angularjs

Short version

To ensure that Angular applications work on IE, confirm the following:

1. polyfill JSON. stringify in IE7 or earlier versions. You can use JSON2 or JSON3 for polyfills.
 

<!doctype html> 

2. Add id = "ng-app" to the root element at the connection, and use the ng-app attribute
 

<!doctype html> 

3. You cannot use custom element tags, such as <ng: view> (use Attribute version <div ng-view> instead), or

4. If you must use custom element tags, you must take the following steps to ensure that IE8 and earlier versions can be used:
 

<!doctype html> 

5. Replace style = "{someCss}" with the ng-style flag }}". Later versions can work in Chrome and Firefox, but cannot work in IE version <= 11 (the latest version when writing this article ).


Important part:

  • Xmlns: ng-namespace-you need to specify a namespace for each custom tag.
  • Document. createElement (yourTagName)-create a custom tag name-because this is only a problem with the earlier version of IE, You need to specify the loading conditions. For each tag that does not have a namespace and is not defined in HTML, You need to declare it in advance so that IE can recognize it.

Version Information

IE has many problems with non-standard label elements. These problems can be categorized into two categories, each of which has its own solution.

  • If the tag name starts with "my:", it is treated as an XML namespace and must have a corresponding namespace declaration.
  • If the tag does not have a symbol but is not a standard HTML tag, you must use document. createElement ('My-tag') to create it in advance.
  • If you plan to use the CSS selector to change the style of the custom tag, you must use document. createElement ('My-tag') to create a custom tag no matter whether there is a namespace.


Good news

The good news is that these restrictions only apply to element tag names and not to element attribute names. Therefore, no special processing is required in IE: <div my-tag your: tag> </div>
What will happen if I don't do this?

Assume that you use the unknown HTML tag mytag (the result of my: tag or my-tag is the same ):

 

 

The following DOM should be parsed:
 

#document +- HTML   +- BODY    +- mytag      +- #text: some text

The expected behavior is that the BODY element has a mytag sub-element with some text.

But this is not true in IE (if the above revision is not included)
 

#document +- HTML   +- BODY    +- mytag    +- #text: some text    +- /mytag

In IE, the BODY element has three child elements:

1. A self-disabled mytag. For example, disable a tag <br/>. /Is optional, but the <br> label does not allow sub-elements. The browser regards <br> some text </br> as the tags of three peers, some text is not a child element of <br>.

2. some text is a text node. This should be a child element of mytag, not a peer tag.

3. A corrupted self-disabled/mytag. This is a corrupt element because the element name cannot contain/characters. In addition, the seed closed element is not part of the DOM. It is only used to describe the DOM structure.

CSS-style custom tag name

To ensure that the CSS selector can work on custom elements, the names of custom elements must be created using document. createElement ('My-tag') in advance without worrying about the XML namespace.
 

<Html xmlns: ng = "needed for ng: namespace"> 

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.