Reputation: 575
I have the following html code
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Current Tour</title>
<!-- cordova -->
<script type="text/javascript" src="../cordova.js"></script>
<!-- jquery -->
<link rel="stylesheet" href="../jquery/jquery.mobile-1.3.2.min.css">
<script type="text/javascript" src="../jquery/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="../jquery/jquery.mobile-1.3.2.min.js"></script>
</head>
<body>
<!-- firebase database -->
<script type='text/javascript' src='https://cdn.firebase.com/v0/firebase.js'></script>
<!-- current_tour.js -->
<script src="../js/current_tour.js"></script>
<h1>Current Tour</h1>
</body>
</html>
and following javascript
var trip_id;
function onDeviceReady() {
alert('device ready');
var fb_id_ref = new Firebase('https://trip- chronicle.firebaseio.com/'+window.localStorage.getItem("fb_id"));
console.log("**DEBUG**: Connected to firebase");
var facebook_id = fb_id_ref.name();
fb_id_ref.on('child_added', function(childSnapShot){
console.log("**DEBUG**: fireBaseRef.on()");
trip_id = childSnapShot.ref();
alert(trip_id);
});
}
document.addEventListener("deviceready", onDeviceReady, false);
If I create some button and call onDeviceReady with button onclick event, it works fine. But, if I try to call onDeviceReady with event listener deviceready I get this error: Uncaught reference error: Firebase is not defined.
Upvotes: 1
Views: 1404
Reputation: 39532
deviceReady
indicates that the PhoneGap API is ready, not that your external JavaScript has finished loading ( http://docs.phonegap.com/en/1.0.0/phonegap_events_events.md.html ).
Instead, you should use the traditional load
event.
Upvotes: 1