如何根据用户使用的浏览器重定向我的页面
How to redirect my page based on the browsers the user uses?
我有3个索引页,比如
index_ch.jsp,index_ie.jsp,index_me.jsp
和一个名为的主父页面
browserdetect.jsp
当用户第一次在browserbrowserdetect.jsp中输入我的url时。。。。。。我需要的是可以放在我的browserdetect.jsp中的jquery或java脚本,它将首先检测用户使用的浏览器,然后根据他或她使用的浏览器重定向到相应的索引页。。。。。。有人能帮我吗
将这个脚本添加到我的头部分帮助我完成了我想要的。。。。谢谢你们的帮助
if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0))
{
window.location.replace("your page");
}
else if (navigator.userAgent.indexOf('Chrome') >= 0)
{
window.location.replace("your page");
}
else
{
window.location.replace("your page");
}
</script>
此代码帮助您检测用户的浏览器。
var x="发送的用户代理标头:"+navigator.userAgent;
我想你想检测用户的浏览器
if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0))
{
the code of index_ie.jsp...
}
else if (navigator.userAgent.indexOf('Chrome') >= 0)
{
the code of index_ch.jsp...
}
else
{
the code of index_me.jsp...
}
browserdetect.jsp ------page
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function detectBrowser(){
var nAgent = navigator.userAgent;
var verOffset;
if ((nAgent.indexOf("MSIE"))!=-1) {
browserName = "Microsoft Internet Explorer";
window.location = "index_ie.jsp";
}
else if ((verOffset=nAgent.indexOf("Chrome"))!=-1) {
browserName = "Chrome";
window.location = "index_ch.jsp";
}
else if ((verOffset=nAgent.indexOf("Firefox"))!=-1) {
browserName = "Firefox";
window.location = "index_me.jsp";
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body onload="detectBrowser()">
<h1>Hello World!</h1>
</body>
</html>
===============================================================================
index_ch.jsp -----page
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World! Chrome</h1>
</body>
</html>
=========================================================================
index_ie.jsp -----page
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World! Internet Explorer</h1>
</body>
</html>
=============================================================================
index_me.jsp -----page
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World! Mozilla Firefox</h1>
</body>
</html>
you can use jsp redirecting tags
1. jsp:forward :- server side redirect [not show index_ie.jsp in the URL]
2. response.sendRedirect :-browser side redirect[ show index_ie.jsp in the URL]
instead of window .location.
相关文章:
- 重定向时角度刷新浏览器
- 防止从浏览器到应用商店的不需要的重定向
- 将用户重定向到 Windows 8 中的桌面浏览器
- 什么'这是重定向不受支持的浏览器的最简单方法
- 按下浏览器后退按钮时将用户重定向到其他页面
- 从chrome浏览器网址打开应用程序或使用javascript重定向到Google Play
- AngularJS仅在浏览器的后退按钮上重定向路由
- 在所有浏览器上执行没有扩展名.js外部脚本重定向
- 弹出窗口重定向在IE中不起作用,但在其他浏览器中可以
- 让 Chrome 和 Safari 浏览器在重定向后显示缓存的页面
- 在子文件夹中检测到浏览器后重定向
- 火狐浏览器拖放重定向停止JQUERY
- 浏览器检测和重定向
- 重定向至document.ready在android浏览器中的另一个页面
- 当网站在非flash浏览器中打开时,重定向至html页面
- window.location.replace()无法重定向浏览器
- 有两个按钮的桌子.一个jQuery-ajax不会'的<表>,而是重定向浏览器到ajax url
- 重定向浏览器版本
- 根据单选按钮值重定向浏览器
- 仅当网站可用时重定向浏览器