Home >Web Front-end >JS Tutorial >Writing scripts compatible with IE and FireFox_javascript skills

Writing scripts compatible with IE and FireFox_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:52:44993browse
1. Formal expression problem
Trying to use the following expression to extract the content after the square brackets "]". The connection calls the following code and it works normally under IE, but FireFox will always replace it with the content of the odd line. Contents of even-numbered lines.
(/(])([^ -}]*)/ig).exec(srcText);
newtext = "[Department]" RegExp.$2;
It was later confirmed that the problem was with "ig" On the "g", FireFox treats RegExp as a global variable and does not update $2 in time. This problem is really inexplicable.
2. Remove Select entries
IE supports select.options.remove(index), but FireFox supports select.remove(index). The compatible method is select.options[i] = null;
3. showModalDialog
FireFox can showModalDialog, but if the page from showModalDialog has a frame, the frame page can be successfully retrieved from window.dialogArguments. FireFox cannot, so you have to use window.parent.dialogArguments to get.
4. childNodes
FF does not have children, so childNodes must be used for compatibility, but IE and FF have inconsistent interpretations. FF regards blank text and line breaks as nodes. In order to avoid the correct node obtained by childNodes(index) , there should be no spaces or line breaks between HTML tags.
5. removeChild
Cannot be used with node.removeNode(true) in FF, change to node.parentNode.removeChild(node).
6. outerHTML
FF does not have node.outerHTML. Call node.parentNode.innerHTML for special processing. If you just add event responses or set attribute values, you can directly element.onclick = function( ){callxxx(x,y);}
7. Script domain problem
The reason for this problem is unknown. FF uses to call external JS and internal script to call lib.js. function, the function is reported as undefined, but IE does not have this problem.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn