Google个性化页面中实例化XMLHTTP对象的方法
Contents
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24function x() { var a=null; try { a=new ActiveXObject(["Msxml2.XMLHTTP"](http://www.microsoft.com/china/technet/community/scriptcenter/resources/hey0222.mspx)); } catch(c) { try { a=new ActiveXObject(["Microsoft.XMLHTTP"](http://www.knowsky.com/5190.html)); } catch(b) { a=null; } } if(!a&&typeof XMLHttpRequest!="undefined") { a=new [XMLHttpRequest](http://developer.apple.com/internet/webcontent/xmlhttpreq.html)(); } return a; }
这个实例化方法至少支持IE、Firefox、Opera和Safari,它的一大特色是用了try…catch…,而不是经常用的if…else…,这种方式是比较稳妥和有效的。
Author
LastMod 2005-07-22