這不是一個最好的方法,因爲很多時候JS並不支持移動瀏覽器。
您可以使用此功能:
function its_mobile_browser($user_agent = '')
{
if (empty($user_agent))
{
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if (empty($user_agent)) return false;
}
if (stripos($user_agent, 'Explorer')!==false ||
stripos($user_agent, 'Windows')!==false ||
stripos($user_agent, 'Win NT')!==false ||
stripos($user_agent, 'FireFox')!==false ||
stripos($user_agent, 'linux')!==false ||
stripos($user_agent, 'unix')!==false ||
stripos($user_agent, 'Macintosh')!==false
)
{
if (!(stripos($user_agent, 'Opera Mini')!==false
|| stripos($user_agent, 'WAP')!==false
|| stripos($user_agent, 'Mobile')!==false
|| stripos($user_agent, 'Symbian')!==false
|| stripos($user_agent, 'NetFront')!==false
|| stripos($user_agent, ' PPC')!==false
|| stripos($user_agent, 'iPhone')!==false
|| stripos($user_agent, 'Android')!==false
|| stripos($user_agent, 'Nokia')!==false
|| stripos($user_agent, 'Samsung')!==false
|| stripos($user_agent, 'SonyEricsson')!==false
|| stripos($user_agent, 'LG')!==false
|| stripos($user_agent, 'Obigo')!==false
|| stripos($user_agent, 'SEC-SGHX')!==false
|| stripos($user_agent, 'Fly')!==false
|| stripos($user_agent, 'MOT-')!==false
|| stripos($user_agent, 'Motorola')!==false
)
) return false;
}
return true;
}
或者更好的東西,哈哈:)
歡迎SO。下一次,請忽略所有'哈哈',需要幫助和問候;前兩個只是煩人的,最後一個是沒有必要的。我也喜歡[Alots](http://hyperboleandahalf.blogspot.com/2010/04/alot-is-better-than-you-at-everything.html)。 – 2011-04-30 22:18:35
如果答案幫助你,請接受/投票,以便其他用戶可以輕鬆找到解決方案,他們絆倒同樣的問題 – neebz 2011-05-01 00:15:26