开发者

HTML - Recomnended href link sytanx [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current开发者_运维知识库 form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

we can give the href like the following

<a href="images\image.png">

<a href="images/image.png">

<a href=".\images\image.png">

<a href="./images/image.png">

which is the recommended method... which doesnot have problem on any browser and on any web server....

leave the image type... consider the link\paths

and PLEASE explain why the specific one


second and last one are correct. Backslash is not a good idea on the web. The ./ is nice but if you're using url rewrites your images won't play along nice.

I would personally prefer the second method, because you drop useless code (the ./), so saving a few bits ;-)


Backslash character is not allowed in URL's except when URL encoded, so always use forward slashes (/). Also, the second and last example are identical, both point to files relative to the current directory. Use whichever you like.


These should do just fine:

<a href="images/image.png">...</a>
<a href="http://yourdomain.com/images/image.png">...</a>

You could even use relative paths, like:

<a href="../images/image.png">...</a>
<a href="/images/image.png">...</a>


Its a common error to use backslash (\) instead of slash (/). Some browsers can understand backslash wrong way (e.g. Netscape).

Its not a secret, that most web servers work under UNIX-based systems, where slash is used as delimiter in file-paths, thats why it is "more friendly" to use slash instead of backslash.

Dot before slash (./ and .\) means, that its relative (to current directory) link. Links like /some/path/ (begin with slash without dot) mean, that your link is relative too, but this case to your website's root.


like joggink said, first one and last one is correct. Why? there is no why, it's just the way the link path should look like. not only for links put for other paths like the img tag


The forward slash is used for file paths in Unix & Linux, whilst the backward slash is used for file hierachy on windows. For internet URLS forward slash is used.

So it depends on what the URL is pointing to and what server your running on.


Use the following if possible:

<a href="/images/image.png" />

The reason being that using \ is not legitimate for directories and using relative paths (images/image.png) could cause issues if you are using a template and the URL for the loaded page is in a subfolder (or the CMS/framework you are using makes it appear to be in a subfolder). For example, if you are at the following URL:

/content/index.php

The browser will attempt to find the image in the following location:

/content/images/image.png

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜