Upload Js file to HTML

My first PhoneGap application has 2 HTML files.

The first is called index.html , which uses index.js . A list item will be displayed in this file. When I click an item in this list, it brings me to the detail.html file as follows:

  $.mobile.changePage("detail.html", { transition: "slideup"}); 

OR

  location.href = "detail.html"; 

On the detail.html page, detail.html load detal.js . However, this did not work. I could not use functions in detail.js .

Please give me your advice and is there any example?

Capture photo

  <link rel="stylesheet" href="css/jquery.mobile.structure-1.3.0.min.css" /> <link rel="stylesheet" href="css/jquery.mobile-1.3.0.min.css" /> <link rel="stylesheet" href="css/getAbstract.min.css" /> <script src="js/jquery-1.9.0.min.js"></script> <script src="js/jquery.mobile-1.3.0.min.js"></script> <script src="js/jquery.ba-dotimeout.js"></script> <script src="js/jquery.dst.js"></script> <script type="text/javascript" charset="utf-8" src="js/cordova-2.5.0.js"></script> <script type="text/javascript" charset="utf-8"></script> </head> <body> <div data-role = "page" data-theme = "a" id = "pageContainer"> <!--Start Page Header --> <div data-role = "header" id = "pageHeader" data-nobackbtn = "true" data-position = "fixed"> <h1>Camera</h1> </div> <!--End Page Header --> <!--Start Page Content--> <div data-role = "content" id= "pageContent"> <a data-role = "button" id = "btnCaptureEdit" href = "">Capture Edit</a> <a data-role = "button" id = "btnLibraryPhoto" href = "">Get Photo From Library</a> <a data-role = "button" id = "btnAlbumPhoto" href = "">Get Photo From Album</a> </div> <!--End Page Content--> <!--Start Page Footer--> <div data-role = "footer" id = "pageFooter"> </div> <!--End Page Footer--> </div> <script src="js/detail.js"></script> </body> </html> 
+7
source share
2 answers

If this is your detail.html , I don’t see where you are loading detail.js ? Perhaps it

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

must be specified

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

?

+8
source

I had the same problem and found the answer. If you are using node.js with express, you need to give it your own function so that the js file is accessible. For instance:

 const script = path.join(__dirname, 'script.js'); const server = express().get('/', (req, res) => res.sendFile(script)) 
0
source

All Articles