2013-04-28 74 views
0

我正在構建一個使用Python在後端和前端作爲HTML,JS,Ajax等web服務。我的web服務有一個特殊的需要,它有兩個不同類型的響應爲那些訪問使用Android設備或iPhone或其他設備PC,Mac等)。如何檢測其用戶訪問我的網站的Android或iPhone?

我想根據他們的設備類型註冊用戶(在我的網站上)併爲每個設備分配一個特定的UId。

那麼是否有可能檢測訪問我的網站的設備類型,並讓他們根據其設備類型訪問服務?

任何JavaScript或jQuery的方式可能嗎?

請建議。

+0

採取兩種方法的JavaScript方式看到此http://計算器.com/questions/3514784/what-is-best-way-to-detect-a-handheld-device-in-jquery – Elior 2013-04-28 12:08:28

+0

要查找的關鍵字是** user-agent ** – waqaslam 2013-04-28 12:09:33

回答

0

這是檢測的JavaScript方式機器人

var ua = navigator.userAgent.toLowerCase(); 
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile"); 
if(isAndroid) { 
    // Do something! 
    // Redirect to Android-site? 
    window.location = 'http://android.davidwalsh.name'; 
} 

這是檢測IPhone

if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { 
    if (document.cookie.indexOf("iphone_redirect=false") == -1) window.location = "http://m.espn.go.com/wireless/?iphone&i=COMR"; 
} 

http://davidwalsh.name/

相關問題