基於浏覽器類型的重定向的實現可以通過使用javascript函數來檢查navigator.userAgent的字符串“MSIE”,它將告訴你用戶是否使用Microsoft Internet Explorer(微軟的IE浏覽器)。通過修改windows.location函數可以重定向到正確的URL(同意資源定位器)。下面是詳細的代碼:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function redirectClient(ieurl, nsurl) {
// test for Internet Explorer (any version)
if (navigator.userAgent.indexOf("MSIE") != -1) {
window.location = ieurl;
} else {
// it's not IE so assume it's Netscape
window.location = nsurl;
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
Click <A HREF="javascript:redirectClient('explorer.html',
'netscape.html')">here</A>
to redirect based on the user's browser.
</BODY>
</HTML>
點擊此處去測試效果頁