Why the third path is not working? Is there any way to use this image without changing the HTML file and image location?
Hi, this is because you are attempting to use an absolute file path while html will try to interpret this as a relative path as always. In your example, let’s say you have your project stored in D:\project\imgDisplay
, then locally me.jpg
refers to D:\project\imgDisplay\me.jpg
. And D:\Image\laksham.jpg
refers to D:\project\imgDisplay\D:\Imge\laksham.jpg
which is nonsense.
The relative file path is very useful, it means when you host the project, the me.jpg
will be at https://localhost/imgDisplay/me.jpg
and the src
property will still have a valid value. In the case of absolute path this is not possible.
But if you have to use an absolute file path, use file:///
in front so html knows this is an absolute file path, e.g. file:///D:\Image\laksham.jpg
. And this will not load when the webpage is hosted.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.