Search code examples
javascriptandroidcordovaphonegap-build

PhoneGap relative protocol issues


I have some Javascript for an API (SoundCloud) which I load into my PhoneGap app remotely and there are obvious issues with any asset that uses a relative protocol as PhoneGap will be using file://

So for any assets pointing to a relative protocol such as //foo.bar/api.js the PhoneGap app will try to fetch file://foo.bar/api.js which of course does not exist.

I do not have access to edit the API related assets. How can I solve this issue?


Solution

  • The easiest way is probably to just download the sdk, edit it (as in add the protocol) and just deliver it with your App.

    As far as I know you can't just change the location.protocol property to make that work so everything else will be quite hacky so you should really stick to the first solution.

    However, you could just get all "script" tags, iterate over them and check the src. If the src starts with an "//" you just create a new script node with the "http://" + element.src to load it properly. You'd most likely need to run that with a little timeout which slows down the whole App quite a bit and if a coworker of mine would do something like that I'd probably hit him but you know, it would work ;)

    • Ben