10

Let's say I have a mobile website that uses root url paths for including assets, such as the following:

<link rel="stylesheet" href="/_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="/_assets/css/jquery.mobile.structure-1.0.min.css" />

In PhoneGap, it does not appear that I can link to the files in that manner. On my index.html file they would have to be relative paths, such as:

<link rel="stylesheet" href="_assets/css/jquery.mobile.theme.css" />

But what about a file located deep in my directory structure, like /sub/dir/index.html. Using relative paths I would have to use the following:

<link rel="stylesheet" href="../../_assets/css/jquery.mobile.theme.css" />

Is it possible to refer to this file in some absolute manner? I have tried the following without success:

<link rel="stylesheet" href="/www/_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="file:///www/_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="file://www/_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="local:///www/_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="local://www/_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="file:///_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="file://_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="local:///_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="local://_assets/css/jquery.mobile.theme.css" />

and probably even a few more just to try. I would really prefer to not have to use relative urls, so hopefuly there is something possible.

Matt
  • 328
  • 3
  • 9

3 Answers3

2

I suggest checking PhoneGap on iOS with absolute path URLs for assets? the second answer shows the "true" absolut path which is something like this: file:///var/mobile/Applications/7D6D107B-D9DC-479B-9E22-4847F0CA0C40/YourApplication.app/www/... Not something i'd rely on.

Community
  • 1
  • 1
Alex M.
  • 51
  • 4
0

I have the same problem with images on Android. In the local browser works fine, but when I deploy the app on my Android device the images wont load.

In the jquery mobile example I replace _assets directory to assets and then changes the urls to point to this folder and it works for me.

Adrian
  • 73
  • 4
  • 1
    I forgot: You must change the path in all your html, css or js files: `for i in $(grep "_assets" * -R | cut -d ":" -f 1); do sed "s/_assets/assets/gi" -i $i; done` – Adrian Aug 01 '12 at 20:26
0

I think the correct href is (for example, jquery.mobile.theme.css):

    "file:///www/android_assets/css/jquery.mobile.theme.css"
Th0rndike
  • 3,406
  • 3
  • 22
  • 42