How to make a picture link with HTML?

百般思念 提交于 2019-12-12 04:28:32

问题


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.



来源:https://stackoverflow.com/questions/7180633/how-to-make-a-picture-link-with-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!