7

I'm trying out Phonegap to develop for both Android and iOS using the same source.

I would like to use absolute paths like :

background-image: url(/graphics/test.png);

but this doesn't work on Android or iOS.

I found out that for Android I have to use something like :

background-image: url(file:///android_asset/www/graphics/test.png);

but of course this doesn't make sense in a browser (for testing the app) and on iOS.

The problem is that I'm using a framework that uses absolute paths all the time.

I tried setting a BASE tag but couldn't get it to work...

Is there any way to use the same absolute paths on all platforms?

Dylan
  • 9,129
  • 20
  • 96
  • 153
  • I understand that it doesn't work like you would hope, but why would you need absolute paths? Particularly for css background images where you know where the file is relative to the css call? – Devgeeks Apr 02 '12 at 00:39
  • The framework I mentioned uses a lot of includes, so snippets or files are included in other files. This way it's quite hard to keep it relative, that's why a lot of links are absolute in the framework. I'm just hoping there's a way to keep those links the same, since I use the framework in my other web projects too. – Dylan Apr 02 '12 at 01:05
  • I have the same problem. When I start my index.html file in the DroidGap view the log says: baseUrl=file:///android_asset/www/ but then absolute path references to files that are under that path don't work. When set via *base* tag in html I get the same result....seems like baseUrl doesn't affect absolute paths. – Andrew Mackenzie Jul 06 '12 at 09:54
  • /graphics/test.png is an absolute path (so it try file://graphics/test.png), try graphics/test.png. What's your framework ? it should work with relatives "./your/assets" – sarlam Apr 01 '15 at 09:07

1 Answers1

3

No, you cannot use absolute paths because they're different on all platforms, and there are no plugins or configuration to unify absolute paths.

It's best to try again solving this in the framework that you're using. We may be able to help you with that if you provide information about this framework.

Alternatively, you could serve your www dir from the web (<content src="http://example.org" /> in config.xml), but that means your app only works with an internet connection.

Blaise
  • 13,139
  • 9
  • 69
  • 97