进行移动重定向的最佳方式是什么? [英] What is the best way to do a mobile redirect?

查看:128
本文介绍了进行移动重定向的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信这会被问到很多,但我也知道事情变化很频繁,所以我想知道什么当前最好的方法做一个简单的移动检测和重定向的网站。

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.

我不能覆盖所有手机,但我想至少得到iphones和androids。

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上put 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆