![]() Links have a hash attribute that contains the # and the section that appears after it in the URL, so letâs now walk through all the links in the document and check whether their name attribute is equal to the hash part of the clicked-on link: // First strip off the hash (first character) Now, we need to find the destination: the tag that corresponds to the part after the hash in our clicked-on link. Just to be paranoid, we also check that what weâve got is an A tag, in case weâve missed something: if (() != 'a') return The useful location object tells us about the URL of the document weâre looking at now, so try this: for (var i=0 i ![]() We need to walk through this list, and work out which of the links weâve found are internal. Getting a list of all the links is easy: var allLinks = document.getElementsByTagName('a') Finding Internal Linksįirst, we need to identify all the links in the document, and then work out which of them are internal ones. In this tutorial, weâll use a smattering of JavaScript to ensure that links that are internal to the document scroll the user to their destination, rather than jumping straight there and confusing users. The answer to this problem is to scroll the user through the document to the linked location, like this. When theyâre navigating through a long document, users often are confused or disoriented when they click a link that jumps to another location in that same document.Īre they on the same page, or a different page? Should they scroll more from here? Whatâs going on?
0 Comments
Leave a Reply. |