方法一:推薦
| // 創建一個布爾型變量 var xmlhttp = false; // 檢查使用的是否為IE瀏覽器 try{ // 如果JS的版本大于5 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); alert("You are using Microsoft Internet Explorer."); }catch(e){ // 如果不是,則使用老版本的ActiveX對象 try{ // 如果使用的是IE瀏覽器 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); alert("You are using Microsoft Internet Explorer."); }catch(e){ // 使用非IE瀏覽器 xmlhttp = false; } } // 如果使用的是IE非瀏覽器 if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){ xmlhttp = new XMLHttpRequest(); alert("You are not using Microsoft Internet Explorer."); } |
方法二:
| var xmlhttp; |
新聞熱點
疑難解答