Created
June 7, 2012 05:44
-
-
Save dhavaln/2886774 to your computer and use it in GitHub Desktop.
Include Phonegap/Cordova JS based on the Device
This file contains hidden or 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
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this works for cordova 3.0 ? in my tests this includes right js but onDeviceReady event not happen.