服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

javascript实例教程(7) 利用javascript基于浏览器类型的重定向

基于浏览器类型的重定向的实现可以通过使用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>

点击此处去测试效果页

扫描关注微信公众号