[英]ionic\cordova jsonp works in browser but not on 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應用應刪除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.