Do html links with the "#" symbols in them cause page refresh when clicked?
Seems like a silly question but I can't for the life of me tell. I have just this on a html file:
<a href="#">hello</a>
When I click it, it appends the hash symbol to the end of the present url and to my naked eyes the page do开发者_运维百科esn't seem to be reloading.
Is this correct or is the page actually reloading?
No, the page does not reload. At worse the page will scroll to the top.
Here's more information than you'd want: http://dev.w3.org/html5/spec/Overview.html#scroll-to-fragid
the # in a link is a link to a place on the current page (see link "the name attribute"). it would usually be something like #sectionname as used in wikipedia
The hash in a URL defines a fragment. The purpose of the fragment in a URI is defined here: http://labs.apache.org/webarch/uri/rfc/rfc3986.html#fragment.
URIs can be used in more agents than just browsers, but in the web enviorment, where a resource is identified with a "page", the subresource identified by the fragment is part of the page, and there's no "round-trip to the server" to load a page.
A browser is free to reflow the page as it scrolls to the fragment, but there is no need to "reload" as the term is commonly understood.
As long as they are on the page you are viewing no. If you click a link to another page like example.com/someOtherPage.html#someTag
it will take you to that part of the new page.
Many of the older site used REALLY long pages and just had links from one element to another, because speeds were slow and that way, once the page was loaded you just jumped from part to part without loading.
精彩评论