3 回答

TA貢獻2037條經驗 獲得超6個贊
iPad檢測
通過查看userAgent屬性,您應該能夠檢測到iPad用戶:
var is_iPad = navigator.userAgent.match(/iPad/i) != null;
iPhone / iPod檢測
同樣,platform用于檢查iPhone或iPods等設備的屬性:
function is_iPhone_or_iPod(){
return navigator.platform.match(/i(Phone|Pod))/i)
}
筆記
當它起作用時,通常應該避免執行特定于瀏覽器的檢測,因為它通常不可靠(并且可能被欺騙)。在大多數情況下,最好使用實際的特征檢測,這可以通過Modernizr之類的庫來完成。
正如Brennen的回答所指出的那樣,在Facebook應用程序中執行此檢測時可能會出現問題。請參閱他的答案以處理這種情況。

TA貢獻1876條經驗 獲得超5個贊
我用這個:
function fnIsAppleMobile()
{
if (navigator && navigator.userAgent && navigator.userAgent != null)
{
var strUserAgent = navigator.userAgent.toLowerCase();
var arrMatches = strUserAgent.match(/(iphone|ipod|ipad)/);
if (arrMatches != null)
return true;
} // End if (navigator && navigator.userAgent)
return false;
} // End Function fnIsAppleMobile
var bIsAppleMobile = fnIsAppleMobile(); // TODO: Write complaint to CrApple asking them why they don't update SquirrelFish with bugfixes, then remove
添加回答
舉報