6

I am making remote ajax calls in my phonegap index.html file and the response is an html snippet including relative references to javascript, css and image files on the remote server. In order for the relative references to function properly I include a <base href="http://myserver.com" /> tag in my index.html file.

This works as expected.

However, I would like to also include local CSS/JS/Image files stored in the www directory of my Phonegap Application. As I set the base href to http://myserver.com I can no longer include them using relative URLs (e.g. <script src="phonegap.0.9.5.js"></script>).

My question is: How can I reference these files?

I am hoping that something like this will work (as I am still posting this question, it is not quite that simple): <script src="file:///www/phonegap.0.9.5.js"></script>

Thanks in advance!

Jonas Fischer
  • 61
  • 1
  • 3

3 Answers3

1

Local images I reference with

./assets/img/img.png

and then when I am getting something on the server I remove the starting dot. So when I am testing my application, I use an asset_path variable that either has the dot or not (in your case you could put the full URL).

Luke Ollett
  • 316
  • 2
  • 16
0

alert(document.location.href) inside the index.html gives me the absolute path on Android.

Maybe it works on iOS too.

Stephan
  • 41,764
  • 65
  • 238
  • 329
Simon Brodtmann
  • 141
  • 1
  • 4
-2

You was almost there. Just use absolute paths instead of relative ones (for windows, as was my case):

<script src="file:///C:/webservers/home/www/phonegap.0.9.5.js"></script>
Vitalii Lebediev
  • 632
  • 2
  • 10
  • 19