0

I am trying to display an image on my html site with this piece of code

"<a href='http://www.stonybrook.edu/'><img class='sbu_navbar' alt='Stony Brook University' src=" + 'Users/Natan/NetBeansProjects/Homework Four/TAManager_Solution/images/yale.png' + "></a>";

The important part is this part

src=" + 'Users/Natan/NetBeansProjects/Homework Four/TAManager_Solution/images/yale.png' + "></a>";

I know that the format is weird but I need it that way because I will be replacing the actual path with data from a json file so it won't be hardcoded.

Does anybody know why the absolute path wont work? It displays an image correctly when I use a relative path like this

src=" + './images/SBUWhiteShieldLogo.jpg' + "></a>";

but not an absolute path.

user7959439
  • 137
  • 8
  • `Users/Natan/NetBeansProjects/Homework Four/TAManager_Solution/images/yale.png` is a relative path. Take a look also at [this answer](http://stackoverflow.com/questions/2005079/absolute-vs-relative-urls). – andreim May 04 '17 at 18:12
  • Oh okay. Is there a reason why that relative path doesn't work? The path is outside the folder where the html files are located. The html files are located in the Homework Four folder in another folder called HTML. Is the fact that the path starts all the way at User the reason that it doesnt work? – user7959439 May 04 '17 at 18:20
  • That path is relative to your current path. If you access a HTML page from a location like `http://my-site.com/path1/path2` then your request will go to `http://my-site.com/path1/path2/Users/Natan/NetBeansProjects/Homework Four/TAManager_Solution/images/yale.png`. So your server needs to provide this resource. – andreim May 04 '17 at 18:30
  • _"The path is outside the folder where the html files are located."_ That's probably the issue – j08691 May 04 '17 at 18:45
  • everything is handled locally. no servers involved. @j08691 is there any way to fix this? – user7959439 May 04 '17 at 18:51
  • Ok then if you are requesting your HTML similar to this `file:///D:/_site/my.html` and an image is located at `D:\_img\cats.jpg` then you can reference it absolutely by doing `` or relatively by doing ``. – andreim May 05 '17 at 13:07

0 Answers0