I recently studied xmlhttp, which is quite interesting. I like to make it run normally in both IE6 and firefox, and the background uses dom4j for parsing.
1. Download the http://webfx.eae.net/dhtml/xmlextras/xmlextras.zip package, there is an xmlextras. js, take it out, I used to generate XmlHttp object.
2. in xmlextras. add the following code to js: // check browsersvar ua = navigator. userAgent; var opera =/opera [56789] | opera/[56789]/I. test (ua); var ie =! Opera &/msie [56789]/I. test (ua); // preventing opera to be identified as ievar mozilla =! Opera &/mozilla/[56789]/I. test (ua); // preventing opera to be identified as mz/* end browser checks */
If (mozilla) {XMLDocument. prototype. selectSingleNode = function (tagname) {var result = this. evaluate (tagname, this, null, 0, null); return result. iterateNext ();} XMLDocument. prototype. selectNodes = function (tagname) {var result = this. evaluate (tagname, this, null, 0, null); var xns = new XMLNodes (result); return xns ;}// define a new class to be compatible with selectNodes () in IE ().
Function XMLNodes (result) {this. length = 0; this. pointer = 0; this. array = new Array (); var I = 0; while (this. array [I] = result. iterateNext ())! = Null) I ++; this. length = this. array. length;} XMLNodes. prototype. nextNode = function () {this. pointer ++; return this. array [pointer-1];} XMLNodes. prototype. reset = function () {this. pointer = 0 ;}let firefox support some of the same interfaces as IE. 3. after XmlHttp is returned, if XmlHttp is required. responseXML object, everything works normally in firefox, but it is not often used in ie6, so we need to re-create an XmlDocument: var doc = XmlDocument. create (); doc. loadXML (xmlHttp. responseText); 4. if
Author Blog: http://blog.111cn.net/wuyou/
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