Created
September 11, 2012 02:13
-
-
Save mvickers/3695436 to your computer and use it in GitHub Desktop.
Load Cordova ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<script> | |
var getOS = function { //Just using indexOf() is dirty. Returns iOS/Android/unknown. | |
var iOS = ['iPad', 'iPod', 'iPhone', 'iPhone Simulator'], //TODO: Remove for release - This is just for debugging. | |
tmp = new RegExp('\\((.*?)\\)').exec(navigator.userAgent).slice(1).toString().split('; '), | |
OS, i; | |
for (i=0; i<tmp.length; i++) { | |
if (iOS.lastIndexOf(tmp[i]) !== -1) { | |
OS = 'iOS'; | |
break; | |
} | |
else if (tmp[i].substring(0,7) === 'Android') { | |
OS = 'Android'; | |
break; | |
} | |
} | |
return (typeof OS !== 'undefined') ? OS : 'unknown'; | |
} | |
var loadJS = function(URL) { | |
var e = document.createElement("script"); | |
e.src = URL; | |
e.type="text/javascript"; | |
document.getElementsByTagName("head")[0].appendChild(e); | |
} | |
var loadCordova = function() { //Note: For some reason, we can't (yet) load Google Maps API from here. | |
var OS = getOS(); | |
if (OS === "Android" || OS === "iOS") { | |
loadJS('scripts/cordova-' + getOS().toLowerCase + '-2.0.0.js' ); //Platform specific cordova.js file. | |
} | |
loadCordova(); | |
} | |
</script> | |
<!-- | |
MORE Regular stuff here... | |
--> | |
</head> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wanna why using indexOf() is dirty;thx