|
|
Automated Links
You are here: irt.org | Articles | JavaScript | Location | Automated Links Published on: Saturday 29th March 1997 By: Martin Webb Creating automated links between sections of the same document can be easily performed using JavaScript. Within a document you must first define the top using the <a>, i.e. the Anchor tag:
This then creates an internal link which can be navigated to using the following syntax:
We can extend this to include links to either the next or last anchor, for example:
Using JavaScript these can be automatically generated using a function a counter and multiple calls to the funtion. First define the count variable:
Followed by the links() function that will do all the work:
The 1st line will only create an anchor called end if the parameter passed to the links() function is false. The 2nd line of the function create a links to the top anchor already created within the document. The 3rd line creates a link back to the previously defined anchor created by the links() function. The 4th line creates a new anchor each time the links() function is called. The name of the new anchor is based on the value of link, which is then incremented by +1. The 5th line creates a link to the next anchor that will be created by the links() function. The 6th line creates a links to the end anchor already created within the document. To produce automated links within a document then the following HTML must be placed where a new link is required:
or for the last link:
Obviously this will always show the text ' Top | Last | Next | End ' even when the document is currently at the top or end. As this is untidy the links() function can be further extended to show only ' Next | End ' when the document is at the top, and only ' Top | Last ' when the document is at the bottom:
Feedback on 'Automated Links'
View the profile on Martin Webb and the list of other Articles by Martin Webb. |
-- div -->
|