Skip to content

Instantly share code, notes, and snippets.

@rudemex
Forked from dhavaln/index.html
Created December 4, 2012 14:08
Show Gist options
  • Select an option

  • Save rudemex/4204279 to your computer and use it in GitHub Desktop.

Select an option

Save rudemex/4204279 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.2.0/jquery.mobile-1.2.0.css" >
<script type="text/javascript" charset="utf-8"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.js"></script>
<script type="text/javascript">
function init() {
if(isAndroid()){
$("script").attr("src", "lib/android/cordova-2.2.0.js").appendTo("head");
}else if(isiOS()){
$("script").attr("src", "lib/ios/cordova-2.2.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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment