简体   繁体   English

Phonegap / Cordova中带有插件的多个HTML文件和文件夹?

[英]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. 我正在将自己创建的基于html的Web应用程序过渡到基于Cordova的应用程序,这样我就可以更多地使用设备功能,例如背景音频和类似的东西。 Because of the way I originally developed the application, all or most of the pages are in multiple html files. 由于我最初开发应用程序的方式,所有或大多数页面都位于多个html文件中。 I do know this isn't desired behaviour for cordova, however because of the way its set up, I have to retain this layout. 我确实知道这对cordova来说不是理想的行为,但是由于其设置方式,我必须保留此布局。

How can I use the various cordova plugins across these pages? 如何在这些页面上使用各种cordova插件? 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. 我一直在使用<script src="cordova.js"></script>行为根目录中的index.html文件引用cordova.js文件,并且可以使用,但是我有子目录并且使用时。 ./cordova.js,结果为404,并且插件无法正常工作。

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! 如果有人能让我知道如何在子目录中使用此cordova.js文件,该文件将大有帮助,因为这使我可以在各种文件中使用插件,干杯!

If you can't access the cordova file from your html pages, then it is an path issue, not an cordova issue. 如果您无法从html页面访问cordova文件,那么这是路径问题,而不是cordova问题。

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. 在所有单个html页面上,重要的是,您必须在每一页上侦听cordova deviceready事件,否则您的插件将无法工作。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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