Javascript src link

Asked

Viewed 32 times

1

Boas, I have the following code, in a function Javascript,

function(){           
   var noDataIcon = document.createElement("img");

   noDataIcon.src = "~/Images/delete_database.png";

}

happened to give me error in src, can not find the image.

How do I solve this problem?

Thank you

  • Fix the image path the code is correct. :)

  • already corrected, it is in this folder, but still giving error

  • 1

    "Images"... I think the "I" is tiny.

  • Thanks, it worked but I had to remove the ~

1 answer

1

How do I solve this problem?

Not using this notation:

"~/Images/delete_database.png";

It is only valid within the server code. Not in client code.

Use instead:

noDataIcon.src = "/Images/delete_database.png";

If the application is in a subdirectory, you may need to process the address.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.