简体   繁体   English

如何使用cordova在index.js中添加函数“ new page”

[英]How to add my function “new page” in my index.js with cordova

I'm pretty new in mobile app developpement and I would like to know how to simplify my code. 我在移动应用程序开发方面还很陌生,我想知道如何简化我的代码。 I would like to add my script in my index.js page. 我想将脚本添加到index.js页面中。

You can see my function to go to another page it's working but I don't like to have my javascript code in the same page than my html/css code. 您可以看到我的功能可以转到另一个正在运行的页面,但是我不希望将我的javascript代码与html / css代码放在同一页面中。

Thank you :) 谢谢 :)

 (function () { "use strict"; document.addEventListener( 'deviceready', onDeviceReady.bind( this ), false ); function onDeviceReady() { // Gérer les événements de suspension et de reprise Cordova document.addEventListener( 'pause', onPause.bind( this ), false ); document.addEventListener('resume', onResume.bind(this), false); document.getElementById("goPageOne").onclick = function goPageOne(); // TODO: Cordova a été chargé. Effectuez l'initialisation qui nécessite Cordova ici. var parentElement = document.getElementById('deviceready'); var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received'); listeningElement.setAttribute('style', 'display:none;'); receivedElement.setAttribute('style', 'display:block;'); // ajout d'une fonction vibration //navigator.vibrate(2000); }; function onPause() { // TODO: cette application a été suspendue. Enregistrez l'état de l'application ici. }; function onResume() { // TODO: cette application a été réactivée. Restaurez l'état de l'application ici. }; //Function go to another page }); 
 <button id="goPageOne">Memo</button> <script type="text/javascript"> document.getElementById("goPageOne").onclick = function () { location.href = "../www/homememo.html"; }; </script> 

Ok there is something weid with the window.open of cordova so I've just changed the function by something more simple without any function. 好的,cordova的window.open有一些奇怪的地方,所以我只是简单地更改了功能,没有任何功能。 I have replaced the function by an href like : 我已经用href代替了该功能:

 <form action="index.html"> <button type="submit" id="b1">Quitter</button> </form> 

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

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