This article is a daily summary of some js compatibility issues and Compatibility Analysis of IE and Firefox and other common browsers, if you are interested in js browser compatibility, learn it together. This article is a daily summary of js compatibility issues and Compatibility Analysis of IE and Firefox and other commonly used browsers, if you are interested in js browser compatibility, join us!
1. children and childNodes
The behaviors of children, childNodes and childNodes in firefox provided by IE are different. In firefox, childNodes counts line breaks and blank characters as child nodes of the parent node, but IE's childNodes and children won't. For example:
yizhu2000
P whose d is dd can be viewed in childNodes in IE. The number of subnodes is 1, and the number of subnodes in ff is 3, we can see from the dom viewer of firefox that its childNodes is ["\ n", p, "\ n"].
To simulate the children attribute in firefox, we can do this:
if (typeof(HTMLElement) != "undefined" && !window.opera) {HTMLElement.prototype.__defineGetter__("children", function() {for (var a = [], j = 0, n, i = 0; i < this.childNodes.length; i++) {n = this.childNodes[i];if (n.nodeType == 1) {a[j++] = n;if (n.name) {if (!a[n.name])a[n.name] = [];a[n.name][a[n.name].length] = n;}if (n.id)a[n.id] = n;}}return a;});}
2. firefox and ie events
Window. event can only be used in IE, but not in Firefox, because Firefox event can only be used in the event. Firefox must be added to the source for parameter transfer. IE ignores this parameter and uses window. event to read this event.
For example, the following method is used to obtain the mouse position under ie:
Obtain the abscissa of mouse clicks