Xander
Xander

Reputation: 1011

Device ready function not firing alert?

I'm attempting to use the cordova local notifications plugin and from what I can see it won't work until a device ready function is activated.

I've seen quite a few questions on StackOverflow and I've tried to implement the solution below, however when I build the app (Using PhoneGap build) the alert inside the device ready function simply isn't appearing.

I'll try to keep my code as minified as possible.

config:

<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns   = "http://www.w3.org/ns/widgets"
    xmlns:gap   = "http://phonegap.com/ns/1.0"
    id          = "com.phonegap.example"
    version     = "1.0.1" >

  <name>1.0.1</name>

  <description>
      hgfdngf
  </description>

  <author href="https://build.phonegap.com" email="*****">
      ****
  </author>

    <content src="index.html" />

    <plugin name="org.apache.cordova.device" />
    <plugin name="de.appplant.cordova.plugin.local-notification" />

</widget>

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <title>NRL</title>
    <link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300" rel="stylesheet">
    <link rel="stylesheet" href="css/main.css"> <!-- Link to main style sheet -->
    <script src="js/jquery-1.12.4.min.js"></script>
    <link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css">
    <script src="js/jquery.mobile-1.4.5.min.js"></script>-->
    <script src="js/javascript.js"></script>
</head>

    <body onload="onLoad()">

</body>

</html>

JS:

function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
    alert("deviceready");    
}

Upvotes: 1

Views: 81

Answers (1)

L Balsdon
L Balsdon

Reputation: 995

You need to reference cordova.js like this

 <script type="text/javascript" src="cordova.js"></script>

Replace path for your path to cordova.js

Upvotes: 2

Related Questions