iOS / Android检测和重定向 [英] iOS/Android Detect and Redirect
本文介绍了iOS / Android检测和重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
js中的新手让我慢一点:D
需要根据用户使用的os进行重定向。如果ios重定向到x,如果android重定向到y,else..stay在原始地址上。
我的问题:
Newbie in js so take me slow:D Need to make a redirection based on what os the user is using. If ios redirect to x, if android redirect to y, else..stay on the original address. My question:
这些片段是否足够?
<script type="text/javascript"> // <![CDATA[
if ( (navigator.userAgent.indexOf('Android') != -1) ) {
document.location = "y";
} // ]]>
</script>
<script type="text/javascript"> // <![CDATA[
if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
document.location = "x";
} // ]]>
</script>
谢谢!:D
推荐答案
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
if ( isMobile.Android() ) {
document.location.href = "y";
}
else if(isMobile.iOS())
{
document.location.href="x";
}
这篇关于iOS / Android检测和重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文