Search code examples
javascriptimagecordovasvghref

Cordova svg <image xlink:href/> throws Failed to load resource: net::ERR_FILE_NOT_FOUND [file:///android_asset/www/undefined]


I'm building an application with cordova, I have an SVG element in my html with an tag in it. the url of the image comes from my firebase storage, the url works fine. if I directly put the url in my html:

<image xlink:href="url"/>

it works fine and it displays the image. (testing on android, debug).

but what I need to do is set the xlink:href trough javascript so i'm doing:

document.getElementById("imageID").setAttributeNS('http://www.w3.org/1999/xlink', 'href', "the url");

I've also tried:

document.getElementById("imageID").setAttribute('xlink:href', 'the url');

but both these attempts throw this error:

Failed to load resource: net::ERR_FILE_NOT_FOUND [file:///android_asset/www/undefined]

and display the standard url not found image

I cant for the life of me figure why though, the image url works fine.


Solution

  • Fixed, it was an async problem where my retrieve URL function wasn't finished at the point I am calling the url.