做網頁有時候會用到JS偵測IE的版本,以下是偵測Microsoft Internet Explorer版本的三種程式碼! 第一種: 複製代碼 代碼如下: <BR>var browser=navigator.appName <BR>var b_version=navigator.appVersion <BR>var version=b_version.split(";"); <BR>var trim_Version=version[1].replace(/[ ]/g,🎜>var trim_Version=version[1].replace(/[ ]/g,🎜>var trim_Version=version[1].replace(/[ ]/g,🎜>var trim_Version=version[1].replace(/[ ]/g, ""); <BR>if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0") <BR>{ <BR>alert("IE 6.0"); <BR>} <BR>else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0") <BR>{ <BR>alert("IE 7.0"); window.location.href="http://xxxx.com" ;<BR>} <BR>else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE8.0") <BR>{ <BR>alert("IE 8.0"); <BR>} <BR>else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE9.0") <BR>{ <BR>alert("IE 9.0"); <BR>} <BR> 第二種: 複製代碼 代碼如下: <BR>if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion .split(";")[1].replace(/[ ]/g,"")=="MSIE6.0") <BR> { <BR>alert("IE 6.0"); <BR>} <BR>else if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion .split(";")[1].replace(/ [ ]/g,"")=="MSIE7.0") <BR>{ <BR>alert("IE 7.0"); <BR>} <BR>else if(navigator.appName == "Microsoft Internet Explorer " && navigator.appVersion .split(";")[1].replace(/[ ]/g,"")=="MSIE8.0") <BR>{ <BR>alert("IE 8.0"); <BR>} <BR>else if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion .split(";")[1].replace(/[ ]/g,"")=="MSIE9 .0") <BR>{ <BR>alert("IE 9.0"); <BR>} <BR> 第三種: 複製代碼 代碼如下: <BR>if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/7./i)=="7.") <BR>{ <BR>alert("IE 7.0"); <BR>} <BR>else if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/8./i)=="8.") <BR>{ <BR>alert("IE 8.0 "); <BR>} <BR>else if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/9./i)=="9.") <BR>{ <BR> alert("IE 9.0"); <BR>} <BR>else if(navigator.appName == "Microsoft Internet Explorer") <BR>{ <BR>alert("IE 6.0"); <BR>} <BR>