This article mainly introduces how to test the compatibility of IE browser with AngularJS in JavaScript. although with the recent release of Windows 10, IE browser will soon become a history... for more information, see
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.
...
2. Add id = "ng-app" to the root element at the connection, and use the ng-app attribute
...
3. you cannot use custom element tags, such (Use attribute version
), 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:
...
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 handling is required in IE:
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 ):
some text
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, self-closing labels
. /Is optional,
Tags cannot have child elements.
Some text
As a tag of three peers, some text is not
.
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.
...