简体   繁体   中英

local notification plugin does only work in index.html - Cannot read property 'notification' of undefined

Hi I am developing a cordova App (Cordova 3.4.0) and want to display a notification. I installed the local notification plugin like it is described here: https://github.com/katzer/cordova-plugin-local-notifications . Somehow displaying the notification does only work in the index.html file. See here:

<html>
  <head>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/lib/jquery-1.11.0.js"></script>
    <script type="text/javascript" src="js/lib/jquery.mobile-1.4.2.js">
    <script type="text/javascript">
      $(document).ready(function(){
        document.addEventListener("deviceready", function() {
          // window.plugin.notification.local.add({ message: 'Great app!' }); // Works
          location = "nextPage.html";
        }, false);
      })
    </script>
  </head>
</html>

But after calling location = "nextPage.html"; the exactly same code on the other page won't work anymore. I get this error:

Error: Cannot read property 'notification' of undefined.

Any ideas why window.plugin is undefined? my nextPage.html looks exactly like the html above except that I commented out - location = "nextPage.html"; - and commented in - window.plugin.notification.local.add({ message: 'Great app!' }); - . They are in the same folder and I do implement cordova, jquery and jquery mobile.

I got this entry in my config.xml:

<feature name="LocalNotification">
        <param name="android-package" value="de.appplant.cordova.plugin.localnotification.LocalNotification" />
</feature>

Any ideas about what I did wrong? Thanks in advance. Please let me know if you need more information.

this occurs because not load all libraries JS that you need. i've a app, that use plugin notification as soon open it and also asynchronous, but a strange razon plugin notificacion not load. I solved revising the order to load JS.

Revise how and where you load libraries. I hope this help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM