【发布时间】:2016-10-04 06:53:28
【问题描述】:
我有一个 Cordova 应用程序,在从远程服务器下载 CSS/JS 时运行良好,但在从本地 css/js 文件夹加载文件时失败。
这是我的index.html:
<!doctype html>
<html ng-app="myapp.editor" ng-class="'appmode-' + appMode" check-if-touch-device>
<head>
<base href="/">
<meta charset="utf-8">
<!-- <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>My App</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<!-- Here are the CSS/JS files -->
<link rel="stylesheet" type="text/css" href="css/myapp.css">
<script src="js/myapp.js"></script>
</head>
<body ng-strict-di>
<script type="application/json" id="ddd">
console.log('Testing...');
</script>
<div class="container animate-view {{screenTransition}}" ui-view></div>
<script type="text/javascript" src="cordova.js"></script>
</body>
</html>
这里是 config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.weld.myapp" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>My App</name>
<description>,,,</description>
<author email="contact@myapp.test" href="https://www.myapp.test">Weld</author>
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<access origin="https://d12wzx9jhww7k1.cloudfront.net" />
<access origin="https://d3kzdohl1nxwtg.cloudfront.net" />
<access origin="https://ds9izj7ug4pro.cloudfront.net" />
<access origin="https://www.myapp.test" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
<splash src="res/splash_512.png" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<splash src="res/splash_512.png" />
</platform>
<platform name="browser">
<splash src="res/splash_512.png" />
</platform>
<plugin name="cordova-plugin-splashscreen" spec="~4.0.0" />
<icon src="res/myapp_icon.png" />
<engine name="ios" spec="~4.2.1" />
<engine name="android" spec="~5.2.2" />
</widget>
我认为它可能与 Content-Security-Policy 相关,但当我启用它时,我只是得到一个白屏。
【问题讨论】:
-
您尝试在哪个平台/操作系统版本上运行您的代码?您使用哪个cordova-android 或cordova-ios 版本?我的所有 css 和 js 文件都本地存储在我的 cordova 应用程序中,并且到目前为止从未遇到过问题(我使用带有 cordova-android 3.6.4 和 cordova-ios 3.6.3 的 cordova CLI 4.0)。
-
文件是否存储在应有的位置(
www/index.html、www/css/myapp.css和www/js/myapp.js)?
标签: cordova