2011-11-28 132 views
-1

我確定這會被問到很多,但我也知道事情的變化很頻繁,所以我想知道當前對網站進行簡單移動檢測和重定向的最佳方式是什麼。做移動重定向的最佳方式是什麼?

我不能覆蓋所有手機,但我想至少得到iphones和機器人。

由於

+0

「最佳」可能是過於主觀。你能談談你正在使用的技術嗎? – ksindi

+0

這些帖子可能會有所幫助:http://stackoverflow.com/questions/1005153/auto-detect-mobile-browser-via-user-agent和http://stackoverflow.com/questions/8176037/standard-practices-in -detecting-mobile-devices-and-feeding-pages -in-php-and-jque – ksindi

+0

我使用了「htaccess檢測手機瀏覽器」並獲得了一些有前景的點擊。 – JimmyPena

回答

0
<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> 

然後對身體標籤放的onload = 「checkBrowser();」

這是一個非常簡單的方法來做到這一點,但我敢肯定有很多更多的方式.. 希望它能幫助:)

相關問題