Cordova应用程序无法加载本地CSS / JS,但远程正常

时间:2016-10-04 06:53:29

标签: cordova

我有一个从远程服务器下载CSS / JS时运行良好的Cordova应用程序,但是当从本地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有关,但是当我启用它时,我只是得到一个白色屏幕。

1 个答案:

答案 0 :(得分:2)

您正在使用HTML的base tag,它指的是相对于所有资源的URL,如果删除该行,您可以像访问的那样访问js / css文件。否则,您必须将完整路径放到文件中。