How to make a picture link with HTML?

2019-08-17 02:25发布

问题:

I have made a picture link with this code snip:

<a href='feed.php'><img src="C:\xampp\htdocs\Project\Icons\Feed.png"/></a>

But no picture appears on my page, why?

(I'm currently only using my page locally!)

回答1:

It's because you (are trying to) use a local file reference.

Either use the relative path

or

<a href='feed.php'><img src="file:///C:/xampp/htdocs/Project/Icons/Feed.png"/></a>

Please be aware that if you plan to use this 'online' it will fail because of the LOCAL reference.

If you load the page through your webserver you should use:

<a href='feed.php'><img src="/Icons/Feed.png"/></a>

Or

<a href='feed.php'><img src="http://yoursite.local/Icons/Feed.png"/></a>

Or whatever the path to the image is.

I would prefer the relative path (the first) though which enables you to move your page to another domain without your links / images breaking.



回答2:

You can't link local files from a remote web page. This is to prevent webpages from accessing files on the end-user's computer.

Change this: C:\xampp\htdocs\Project\Icons\Feed.png

To this: http://yourwebsitehere.com/Project/Icons/Feed.png

EDIT: Since you say its only used locally, then you need to use this instead: file:///C:/xampp/htdocs/Project/Icons/Feed.png

Also, make sure the image is actually located where you think it is!

Try typing file:///C:/xampp/htdocs/Project/Icons/Feed.png into your browser's address bar and see what happens.