基于浏览器类型的重定向的实现可以通过使用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>
点击此处去测试效果页
<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>
点击此处去测试效果页
闽公网安备 35060202000074号