0

I have the following code in my app (Cordova CLI 5.2).

<script>  
  var onDeviceReady;

  onDeviceReady = function() {
    alert('device ready');
    document.body.style.backgroundColor = "red";
  };

  document.addEventListener('deviceready', onDeviceReady, false);
</script>

However I never see the alert (or background color change) on my Android after I build and install the app using PhoneGap Build. No matter what I do, I can't get this code to work.

Benjamin Humphrey
  • 3,770
  • 2
  • 23
  • 41
  • are you using any other libraries that may conflict .. also have you read http://stackoverflow.com/questions/12576062/jquery-document-ready-vs-phonegap-deviceready – Peter Scott Oct 04 '15 at 00:12
  • I'm using jQuery and a couple of plugins but they shouldn't conflict. I'll try out the method suggested in the second answer. – Benjamin Humphrey Oct 04 '15 at 00:19
  • It's almost like PhoneGap Build isn't including cordova.js. – Benjamin Humphrey Oct 04 '15 at 00:21
  • or something is breaking in a plugin or other included js. I vaguely remember having some conflict in the past because I changed the order of my js includes - is the cordov include in the page ? – Peter Scott Oct 04 '15 at 00:23
  • i assume that you are running on a device or simulator and not in browser. – Peter Scott Oct 04 '15 at 00:25

1 Answers1

1

Okay. I figured it out. I wasn't including phonegap.js in index.html like this:

<script src="phonegap.js"></script>

D'oh.

Benjamin Humphrey
  • 3,770
  • 2
  • 23
  • 41