簡體   English   中英

Cordova項目可在瀏覽器上工作,但不能在android中

[英]Cordova project works on browser but not in android

我遇到一個奇怪的問題,我在Android上的cordova應用程序無法加載js / css文件,如果我在瀏覽器中運行該文件,則不會。

從遠程調試中,我收到以下錯誤消息: file:///css/all.css Failed to load resource: net::ERR_FILE_NOT_FOUND file:///js/shims.js Failed to load resource: net::ERR_FILE_NOT_FOUND file:///js/app.js Failed to load resource: net::ERR_FILE_NOT_FOUND

這是我的項目結構

config.xml
www
   js
     jsFiles
   css
     cssFiles
   app
      more html files
   index.html

我的index.html文件如下所示:

<!DOCTYPE html>
<html lang="en">
<head>
  <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">

  <base href="/">
  <meta charset="utf-8">
  <title>My App</title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="/css/all.css">
</head>
<body>

  <sd-app>Loading...</sd-app>

  <script>
  if (!Object.hasOwnProperty('name')) {
    Object.defineProperty(Function.prototype, 'name', {
      get: function() {
        var matches = this.toString().match(/^\s*function\s*((?![0-9])[a-zA-Z0-9_$]*)\s*\(/);
        var name = matches && matches.length > 1 ? matches[1] : "";

        Object.defineProperty(this, 'name', {value: name});
        return name;
      }
    });
  }
  </script>

  <script>
  // Fixes undefined module function in SystemJS bundle
  function module() {}
  </script>

  <script src="./js/shims.js"></script>
  <script src="./js/app.js"></script>

</body>
</html>

在此處輸入圖片說明

對於任何對未來感興趣的人,我都解決了這個問題,因為我在應用程序中使用angular 2,因此我定義了代碼片段,就像我在代碼段中看到的那樣,是我應用程序的基本網址:

  <base href="/">

這在cordova中成為問題,對於Android / iOS應用應刪除。

如果css和js文件夾與index.html處於同一級別,則應這樣鏈接它們:-

<link href="css/android/prelogin.css" rel="stylesheet">
<script type="text/javascript" src="cordova.js"></script>
<script src="scripts/lib/jquery/jquery.1.9.1.js"></script>
<script src="scripts/lib/jquery/jquery.mobile-1.3.2.js"></script>

請參閱屏幕截圖以更清晰

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM