进行移动重定向的最佳方法是什么? [英] What is the best way to do a mobile redirect?
本文介绍了进行移动重定向的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我确定这个问题经常被问到,但我也知道事情经常发生变化,所以我想知道当前对网站进行简单移动检测和重定向的最佳方法是什么.
I'm sure this gets asked a lot, but I also know things change quite frequently, so I am wondering what the current best way to do a simple mobile detection and redirection for a site is.
我无法覆盖所有手机,但我想至少拥有 iphone 和 android.
I'm not going to be able to cover all phones, but I'd like to at least get iphones and androids.
谢谢
推荐答案
<script type="text/javascript">
function checkBrowser(){
var str=navigator.appVersion;
var patt1=/Android/;
var patt2=/iPhone/;
if(str.match(patt1) || str.match(patt2)){
window.location="http://m.yoursite.com";
}
}
</script>
然后在 body-tag 上放置 onload="checkBrowser();"
then on the body-tag put onload="checkBrowser();"
这是一种非常简单的方法,但我相信还有更多的方法..希望它有帮助:)
it's a very simple way to do it, but i'm sure there plenty more ways.. hope it helps :)
这篇关于进行移动重定向的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文