What does it means when there is fowards slash after a href? [closed]

≡放荡痞女 提交于 2020-01-16 00:51:34

问题


Hello i am a newbie in web development. i am working on coding of a web page and stuck at this line:

<a href="/My_Story">My story</a>

might someone tell me what does forward slash means here i mean when i click my_Story in (view-source-code of ff) it takes me to html coding of 'my story' similarly there are other links like

<a href="/Media">Media</a>
<a href="/Sponsors">Sponsors</a>

so when we click 'Media' or''Sponsors' i am taken to html coding of Media or Sponsors. How this is done?what the slash means?and why does the html code not appears directly WITHOUT clicking My_Story,Media or Sponsors.

Btw you may check the website : http://alexnoren.com/


回答1:


Forward slash at the start of an href means that it's a relative path, starting from the root of the website.

For example, in a page example.com/folder/page.html, an

<a href="newpage.html">

points to example.com/folder/newpage.html, while

<a href="/newpage.html">

points to example.com/newpage.html

Can you explain better the source-code thing?




回答2:


It means path from root of the site.

Examples: If you're in http://example.com/folder/file.html

<a href="/"> means http://example.com/
<a href="/test.html"> means http://example.com/test.html
<a href="test.html"> means http://example.com/folder/test.html

If page where link is appeared is in root itself (main page or page without slashes in path) it's no difference between link with slash and link without slash at all




回答3:


It means that the link will be pointing from the root folder




回答4:


This is what's known as a relative path. Including a forward slash / in the path means "go inside the folder written on the left of this slash" If there is nothing on the left, it treats the folder as the root of the website which in this case is http://alexnoren.com.

After taking a closer look at the alexnoren website it seems that it does not employ the method of navigation mentioned by myself and other people here. The page content is actually accessed through Javascript. When you click on the link you're not really moving to a different page at all, the <a> tags are triggering click event code and bringing content that is offscreen into view. If you disable javascript in your browser you'll see that it no longer works.



来源:https://stackoverflow.com/questions/17772692/what-does-it-means-when-there-is-fowards-slash-after-a-href

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