Skip to content

Instantly share code, notes, and snippets.

@dhavaln
Created June 7, 2012 05:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dhavaln/2886774 to your computer and use it in GitHub Desktop.
Save dhavaln/2886774 to your computer and use it in GitHub Desktop.
Include Phonegap/Cordova JS based on the Device
<!DOCTYPE HTML>
<html>
<!DOCTYPE HTML>
<head>
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>PhoneGap Test</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.css" >
<script type="text/javascript" charset="utf-8"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.js"></script>
<script type="text/javascript">
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");
}
</script>
</head>
<body onload="init();" id="stage" class="theme">
<div data-role="page">
<div data-role="content">
<a data-role="button" href="test/first.html">first</a>
</div>
</div>
</body>
</html>
@avtehnik
Copy link

Is this works for cordova 3.0 ? in my tests this includes right js but onDeviceReady event not happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment