Skip to content

Instantly share code, notes, and snippets.

@videlais
Last active August 29, 2015 14:05
Show Gist options
  • Save videlais/9c66c56655e8a8cac39c to your computer and use it in GitHub Desktop.
Save videlais/9c66c56655e8a8cac39c to your computer and use it in GitHub Desktop.
Detecting Apache Cordova
<!DOCTYPE html>
<html>
<head>
<title>Device Ready Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
// Now safe to use device APIs
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Device Ready Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
var isCordovaApp = (typeof window.cordova !== "undefined");
if(isCordovaApp) {
document.addEventListener("deviceready", loadProject, false);
} else {
loadProject();
}
function loadProject() {
//Load project code here.
}
</script>
</head>
<body>
</body>
</html>
var isCordovaApp = (document.location.protocol === "file:");
var isCordovaApp = (document.URL.indexOf('http://') === -1 && document.URL.indexOf('https://') === -1);
var isCordovaApp = (typeof window.cordova !== "undefined");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment