简体   繁体   中英

Multiple HTML files and Folders in Phonegap/Cordova with plugins?

I'm transitioning an html based web app that I have created to a cordova based app so I can make more use of device functions, such as background audio and things of the sort. Because of the way I originally developed the application, all or most of the pages are in multiple html files. I do know this isn't desired behaviour for cordova, however because of the way its set up, I have to retain this layout.

How can I use the various cordova plugins across these pages? I have been using the <script src="cordova.js"></script> line to reference the cordova.js file for the index.html file in the root directory and that works, however I have subdirectories and when I use ../cordova.js it results in a 404 and the plugins don't work.

If anyone could let me know how I can use this cordova.js file in subdirectories that would greatly help out, as this allows me to use plugins in the various files, cheers!

If you can't access the cordova file from your html pages, then it is an path issue, not an cordova issue.

The important thing on all of your single html pages is, that you have to listen on every page for the cordova deviceready event, otherwise your plugins will not work.

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    // Now safe to use device APIs
}

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