Phonegap dev
How to detect different OS in JS code
function init() {
if(isAndroid()){
$("script").attr("src", "lib/android/cordova-1.7.0.js").appendTo("head");
}else if(isiOS()){
$("script").attr("src", "lib/ios/cordova-1.7.0.js").appendTo("head");
}
document.addEventListener("deviceready", onDeviceReady, false);
}
function isAndroid(){
return navigator.userAgent.indexOf("Android") > 0;
}
function isiOS(){
return ( navigator.userAgent.indexOf("iPhone") > 0 || navigator.userAgent.indexOf("iPad") > 0 || navigator.userAgent.indexOf("iPod") > 0);
}
function onDeviceReady(){
console.log("device is ready");
}
© 2010 Marmil (Martin Milička)