0

This may be a pretty basic or stupid question, but I couldn't find the answer online so...

Im using this relative url in JavaScript to add a div with an image. The relative url goes to the path of the image.

I'm not seeing an image and I don't know if that is because the relative url is wrong or something else. Is there any way to test if javascript does or does not find the image from this relative url?

I'll include the part of code, even though I think the problem is clear enough it itself.

$item.find('.item-content').append('<div class="dragable-item"><img 
url="../Content/onderwijs/images/dragicon.png"/></div>');

Thank you in advance!

Daan Proost
  • 119
  • 1
  • 7
  • 2
    Check your network panel in your browser's developer console. It'll help identify what's going on. – random_user_name Apr 26 '19 at 13:34
  • Also note that using a relative url while appending to the DOM will result in the relative link originating from the html file and not your javascript file(if this isn't in the same file that is) – DTul Apr 26 '19 at 13:36
  • you should take a look there, it may help you I think : https://stackoverflow.com/questions/9714525/javascript-image-url-verify – Clément Parayre Apr 26 '19 at 13:37

1 Answers1

0

There is a way to test if JavaScript does or does not find a file. By using fetch you can get the status code. If it's 200 then the file exists.

fetch("../Content/onderwijs/images/dragicon.png").then(function(resp) {
    console.log('Status code is: ', resp.status);
});

From your page you can paste the above code into your console and it would tell you if the file exists.

Steve Lage
  • 692
  • 6
  • 11