简体   繁体   English

JavaScript文件无法在Android PhoneGapped应用中运行,未使用jQuery mobile

[英]JavaScript files not working in Android PhoneGapped app, no jQuery mobile is being used

I have a Hybrid app I built with HTML5, CSS3, JavaScript and some jQuery. 我有一个使用HTML5,CSS3,JavaScript和一些jQuery构建的混合应用程序。 I am also using FireBase to store data. 我还使用FireBase来存储数据。 Everything works good, until I PhoneGap my application to device (Android). 一切正常,直到我将我的应用程序PhoneGap连接到设备(Android)。 It loads server content, so I know the internet is not a problem. 它加载服务器内容,所以我知道互联网不是问题。 The HTML and CSS work fine. HTML和CSS可以正常工作。 But none of the functions work, like my .js files are being ignored. 但是这些功能都不起作用,就像我的.js文件被忽略一样。 Steps taken so far: 到目前为止已采取的步骤:

Ensured <access origin="*" /> is included in the config.xml file, 确保<access origin="*" />包含在config.xml文件中,

Ensured <uses-permission android:name="android.permission.INTERNET" /> is included in the AndroidManifest.xml file, 确保<uses-permission android:name="android.permission.INTERNET" /> Mans <uses-permission android:name="android.permission.INTERNET" />包含在AndroidManifest.xml文件中,

Ensured all <script> tags are included in the <body> tags of each HTML file, 确保所有<script>标记都包含在每个HTML文件的<body>标记中,

Ensured index.html retains the original PhoneGap index.js file with the app init code in it and that all my <script> tags are loaded after that, 确保index.html保留其中包含app init代码的原始PhoneGap index.js文件,并在此之后加载我所有的<script>标签,

Ensured index.html contains all the <script> tags for the project. 确保index.html包含项目的所有<script>标记。

Below is the PhoneGapped index.html file for your inspection: 以下是PhoneGapped index.html文件供您检查:

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
    <meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' gap:; style-src 'self' 'unsafe-inline'; media-src *" />
    <link rel="stylesheet" href="css/customFitStyling.css" type="text/css">
    <link rel="stylesheet" href="css/w3c_v4.css" type="text/css">
    <title>CustomFit</title>
  </head>
  <body>

    <!--CONTENT-->

    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
      app.initialize();
    </script>
    <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="js/customFitFunctions.js"></script>
    <script type="text/javascript" src="js/setFalseBool.js"></script>
  </body>
</html>

对此发表评论。

<!--<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' gap:; style-src 'self' 'unsafe-inline'; media-src *" />-->

I don't know if anyone is interested in this, but I finally figured out he problem. 我不知道是否有人对此感兴趣,但是我终于弄清楚了他的问题。 I have this piece of code at the top of my functions file: 我的函数文件顶部有这段代码:

// Set latest workout.
var title = JSON.parse(localStorage.workout);
$("#latest").text("Latest: " + title.title);

It works absolutely fine on browser and even on phone, it does what its supposed to. 它在浏览器甚至手机上都可以正常工作,它可以完成预期的工作。 But every function coming after that breaks. 但是此后出现的每个功能都会中断。 If I console.log() the localStorage.workout variable, it logs an object containing three arrays, as I expected. 如果我用console.log() localStorage.workout变量,它将记录一个包含三个数组的对象,这与我预期的一样。 If I replace the JSON.parse with this object, the code works the same and all the functions start working again. 如果将JSON.parse替换为该对象,则代码的工作原理相同,所有功能再次开始工作。 Does anyone know what's going on? 有人知道发生了什么吗?

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

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