I am unable to get the device ready function to work within phonegap i.e. xcode simulator. The html is as follow: `
<title>Boilerplate</title>
</head>
<body>
<div id="main" data-role="page">
<div data-role="header" class="logo">
<img class="logo" src="img/premium-logo.jpg" />
</div>
<div data-role="content">
<h1>Apache Cordova Test Zone</h1>
<div class="test-zone" id="test-zone">
</div>
</div>
<div data-role="footer">
<h4>Footer of main page</h4>
</div>
</div>
<script type="text/javascript" src="js/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="js/jQuery-Mobile-1.3.1-min.js"></script>
<script type="text/javascript" src="cordova-2.3.0.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
$(document).ready(init());
</script>
</body>
the Javascript file index.js:
function init() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
alert('It works!');
}
If i comment out the line inside the init function and replace it simply with onDeviceReady(); I can get the alert to work on chrome.
Why won't it work in the simulator with the code above. Thank you
See Question&Answers more detail:os