What is the best way to do a mobile redirect?

前端 未结 1 1642
盖世英雄少女心
盖世英雄少女心 2020-12-22 13:28

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

相关标签:
1条回答
  • 2020-12-22 13:57
    <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>
    

    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 :)

    0 讨论(0)
提交回复
热议问题