admin管理员组文章数量:1568360
http://blog.csdn/li_magic/article/details/53215140
<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" Content="text/html;charset=UTF-8"/>
<title>识别电脑浏览器和手机浏览器</title>
</head>
<script type="text/javascript">
var system ={};
var p = navigator.platform;
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
if(system.win||system.mac||system.xll){
//如果是电脑跳转到百度
window.location.href="http://www.baidu/";
}else{
//如果是手机,跳转到 hao123首页
window.location.href="http://www.hao123/";
}
</script>
<body>
</body>
</html>
js判断是电脑浏览器还是手机端浏览器,并根据不同的终端跳转到不同的网址
[html] view plain copy
- <!DOCTYPE html>
- <html>
- <script>
- function browserRedirect() {
- var sUserAgent = navigator.userAgent.toLowerCase();
- var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
- var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
- var bIsMidp = sUserAgent.match(/midp/i) == "midp";
- var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
- var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
- var bIsAndroid = sUserAgent.match(/android/i) == "android";
- var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
- var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
- if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){
- window.location.href="http://blog.csdn/zml_2015";
- } else {
- window.location.href="http://m.blog.csdn/blog/index?username=zml_2015";
- }
- }
- browserRedirect();
- </script>
- <body>
- </body>
- </html>
js判断手机浏览器操作系统和微信浏览器的方法
投稿:mdxy-dxy 字体:[增加 减小] 类型:转载 时间:2016-04-30 我要评论
做手机端的前端开发,少不了对手机平台的判断。如,对于app下载,就要判断在Android平台下就显示Android下载提示;在iOS平台下就显示iOS下载提示http://www.jb51/article/83344.htm今天就为大家介绍一下用js判断手机客户端平台及系统平台的方法:
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<script type=
"text/javascript"
>
//手机端判断各个平台浏览器及操作系统平台
function
checkPlatform(){
if
(/android/i.test(navigator.userAgent)){
document.write(
"This is Android'browser."
);
//这是Android平台下浏览器
}
if
(/(iPhoneiPadiPodiOS)/i.test(navigator.userAgent)){
document.write(
"This is iOS'browser."
);
//这是iOS平台下浏览器
}
if
(/Linux/i.test(navigator.userAgent)){
document.write(
"This is Linux'browser."
);
//这是Linux平台下浏览器
}
if
(/Linux/i.test(navigator.platform)){
document.write(
"This is Linux operating system."
);
//这是Linux操作系统平台
}
if
(/MicroMessenger/i.test(navigator.userAgent)){
document.write(
"This is MicroMessenger'browser."
);
//这是微信平台下浏览器
}
}
$(document).ready(
function
(){
alert(navigator.platform);
checkPlatform();
});
</script>
|
注意上面的代码使用了jquery。需要加载jquery才可以运行。当然你可以把触发函数给删除了
在这里就不做pc端操作系统平台的判断了,怎么判断也说下方法,如用document.write(navigator.platform);就可以获得操作系统平台。在win32下就会显示Win32,;在Win64下就会显示Win64等。
下面脚本之家小编为大家补充几个不错的函数
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<script type=
"text/javascript"
>
var
browser = {
versions :
function
() {
var
u = navigator.userAgent,
app = navigator.appVersion;
return
{
trident : u.indexOf(
'Trident'
) > -1,
presto : u.indexOf(
'Presto'
) > -1,
webKit : u.indexOf(
'AppleWebKit'
) > -1,
gecko : u.indexOf(
'Gecko'
) > -1 && u.indexOf(
'KHTML'
) == -1,
mobile : !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/),
ios : !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
android : u.indexOf(
'Android'
) > -1 || u.indexOf(
'Linux'
) > -1,
iPhone : u.indexOf(
'iPhone'
) > -1 || u.indexOf(
'Mac'
) > -1,
iPad : u.indexOf(
'iPad'
) > -1,
webApp : u.indexOf(
'Safari'
) == -1,
QQbrw : u.indexOf(
'MQQBrowser'
) > -1,
weiXin : u.indexOf(
'MicroMessenger'
) > -1,
ucLowEnd : u.indexOf(
'UCWEB7.'
) > -1,
ucSpecial : u.indexOf(
'rv:1.2.3.4'
) > -1,
ucweb :
function
() {
try
{
return
parseFloat(u.match(/ucweb\d+\.\d+/gi).toString().match(/\d+\.\d+/).toString()) >= 8.2
}
catch
(e) {
if
(u.indexOf(
'UC'
) > -1) {
return
true
;
}
else
{
return
false
;
}
}
}
(),
Symbian : u.indexOf(
'Symbian'
) > -1,
ucSB : u.indexOf(
'Firefox/1.'
) > -1
};
}
()
}
if
(browser.versions.QQbrw){
document.write(
"qq浏览器"
);
}
else
{
document.write(
"其它浏览器"
);
}
</script>
|
亲测,非常好用。
版权声明:本文标题:JS实现识别电脑浏览器和手机浏览器 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1727157526a1099645.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论