TECHNICAL CONSIDERATIONS |
a discussion of the technical aspects of hypertextual links |
INTRO | Just what are hypertextual links? Put simply, they are defined links between areas of the internet. They are the pieces of text, images or buttons that you click on to move between pages or sites on the world wide web. In short, they are what make the internet work. Despite their importance, however, 'hyperlinks' are extremely easy to create in their basic form. They can be manipulated in a variety of ways, however. This page presents some examples of how hypertextual links can be created and manipulated, from the most basic plain text links to Java-powered drop-down menus and dynamic images. |
BASICS | Basic HTML hyperlinks Before introducing more advanced concepts, it is perhaps best to ensure that standard HTML conventions of hypertext links are known and fully understood by all. A 'hypertext link' (also called 'hyperlink' or simply 'link') is a piece of HTML code that links particular areas of one document to areas of another document (or indeed to other areas of the same document). For example, this link will take you to the bottom of this page, while this link will take you to a completely new website. You may notice that the links are underlined. This is the standard convention used to display which areas of the page are 'links', and is produced automatically by the web browser. There is a difference, however (Internet Explorer displays this, Netscape Navigator does not), which will be demonstrated in code examples. A standard link would be coded as: <a href="the www address"> a link to a world wide web site </a> And would appear in this fashion: a link to a world wide web site When linking to another point in the same document, however, different code is used - note the inclusion of the #: <a href="#any text"> a link to another point in this page </a> In addition, when linking to another area within the same document, the link needs to be 'anchored' - you must tell the browser what area of the document this link will point to. This is achieved with the following code: <a name="any text"> any element or text </a> It is vital that the 'href=#' and 'name=' elements contain the same text, or the link will not work. The 'target' for this internal link is, however, unaffected, and appears in it's normal state. This tag can be used on any object in the area you wish to link to, even <br> or <p> elements - it is not tied to text. Additional commands Several extra elements can be added to the basic 'href' command to provide much greater flexibility. For example, by adding additional code within the main tag, a page creator can direct the browser to load the page being linked to in a variety of ways. Standard links will load the new page over the old, moving the reader away from your site. By forcing the browser to open a new window, however, the reader can visit another page/site while remaining centred on your page. This is achieved with this code: <a href="the www address" target="_blank"> a link to a world wide web site opening in a new window </a> It is the 'target=' command that tells the browser how to load the page. '_blank' tells the browser to load the page into a new, blank window. Other commands are available - '_self', '_parent' and '_top' - experiment and see what they do! Alternatively, a hyperlink can be configured so that instead of redirecting the browser to a new web page/site, it opens the users email package with a new email message addressed to whoever you wish. This is achieved by the addition of the 'mailto' command: <a href="mailto:[email protected]">email somebody</a> This would appear as a normal link. Additional functions can be used in conjunction with the 'mailto' command - perhaps the most useful is the 'subject' command. This allows the designer of the web page to specify the text in the subject line of the email message: <a href="mailto:[email protected]?subject=anything">email somebody</a> Any text can be used, as long as it appears with the speech marks ("). This would appear as: Try clicking and see what happens! Employing images as links Using text as a link is all very well - what about images? HTML is extremely straightforward in this respect. To transform a plain image into a linked image, all one needs to do is enclose the image tag in the 'href' tag: <a href="the www address"><img src="image filename"></a> Unfortunately, this basic command creates a halo-like border around the image, to show that it is a link. This can, however, be countered by including the command 'border=0' in the image tag: <img src="image filename" border=0> Simple. |
JAVASCRIPT | Status bar messages It is all very well creating plain links. But what if you wish to provide a little more information on the page the link leads to? In normal circumstances, when the mouse-pointer passes over a link, the URL of the page linked to appears in the browser status bar (the small bar at the bottom of the window). This feature can, however, be manipulated. With a little coding, you can call upon the Java abilities of most browsers to display a short message in the status bar. The code, as follows, is included in the 'a href' tag, and takes advantage of the Java 'onmouseover' feature: <a href="the URL" onMouseover="window.status='short description / message'; return true" onMouseout="window.status=' '; return true">a link</a> It
is the term 'window.status=' that tells the browser to place the following message in the status bar. Any message can be used, as long as it is contained within 's. In addition, it is conventional to include the 'onmouseout' command, telling the browser to remove text from the status bar by using the blank term 'window.status=' '' - a blank version of that included in this onmouseover command. The link will then look like this (pay attention to the status bar!): WARNING: Do not make your message too long, or it will be cut down to fit the limited space available in the status bar. So keep it short and sweet! Step back Most browsers have a 'back' feature - but how does this work, and how can you present a 'back' button on your page that works in similar fashion? Quite simply, the browser 'back' function recalls pages stored in its 'history' - it remembers the pages you have visited, and stores their address should you wish to return to them. In web pages, however, 'back' functions that have been coded by the web-page creator cannot usually operate in this way. Instead, the link is 'anchored' to a particular page, providing a logical sequence of pages - this was the last, this is next, and so on. This can be a problem when creating a hyperfiction, as such fictions to not operate in a logical sequence. Instead, the reader jumps around a stack of pages almost randomly. Moving 'back' using a link provided on the webpage would in all probability not therefore move the reader back to the page they had previously visited, but to the page one step back in the logical sequence provided by the coder. How can this be avoided? Once more, Javascript provides the answer. With a little code, a 'back' link on a webpage can point not to a particular page, but can call upon the 'history' store of the browser. The link will appear as normal, but the 'a href' code is a little more complex: <a href="javascript:history.go(-1)">link back</a> The code is quite self-explanatory. The Javascript merely tells the browser that this link points to the page before this (history-1) - the last page. Quite a useful command... but be careful. If you use links that point to different areas on the same page, this command will point not to the last page, but to the last area viewed on that page. You should therefore use this feature sparingly. Menu systems Although it is possible to create a menu system using HTML, this can be quite complex, as it requires 'CGI' scripts (code files that reside on the server and process input information from a HTML source). It is, in the short term, far easier to employ a small piece of Javascript code. As with all Javascript, this code is included in the HTML source document. The code required for a menu system is: <SCRIPT language="JavaScript"> <!-- HIDE JAVASCRIPT FROM OBSOLETE BROWSERS function MakeArray() {function surfto(form) {document.writeln('<FORM><SELECT NAME="SelectMenu" onChange="surfto(this.form)">'); tot = siteopt.length;document.write("<OPTION>" +siteopt[i]); document.writeln('</SELECT>'); if (navigator.userAgent.indexOf("Mozilla/2") != -1);document.writeln('<INPUT TYPE=BUTTON VALUE="Go!">') document.writeln('</FORM>'); //-- STOP HIDING --> </SCRIPT> Quite confusing, eh? Well, we don't really need to understand what is going on - we merely need to know how to use this example. I have highlighted in green the code that provides the items within the drop-down menu. The first section ["menu item",] contains the text that will appear in the menu. The second ["menu item URL",] contains the URL for the page. It is vital that the label and URL for each menu item appear in the same order, else the reader would be directed to the incorrect URL when selecting a particular menu item. Any number of menu items can be included - the only restriction is that the last item on the menu contain ); instead of just a ,. The above
code would produce the following menu (I have deliberately not coded any external URLS, to prevent any leaps to other sites):
Why not have a play and see what you can come up with? Dynamic images Although an interesting way to organise links, menu systems are restrictive, and can look quite boring. An alternative is to use dynamic images as links. 'Dynamic' here means that the image changes when the user's mouse moves across it, displaying the fact that this image has an unusual feature. An extremely useful piece of code, this Javascript is a little more difficult to use than the above menu system. The basic code is: <SCRIPT LANGUAGE="JavaScript"> <!-- HIDE JAVASCRIPT FROM OBSOLETE BROWSERS version = false; if (document.images) { version = true; } if (version == true) { ???on = new Image;} function rollon(imgName) { if (version == true) { imgOn = eval(imgName + "on.src"); document [imgName].src = imgOn; } } function rolloff(imgName) { if (version == true) { imgOff = eval(imgName + "off.src"); document [imgName].src = imgOff; } } // STOP HIDING --> </SCRIPT> This code provides the basic function 'onmouseover' - in other words, it causes particular elements on the page to change when the mouse moves across them. In this particular example, the code changes an image that has been given the name '???' (this can be any text label). Two images are used - image_mouseon.gif and image_normal.gif. The 'normal' image would be displayed until the mouse moves across the image, when the 'mouseon' image would be displayed. Any number of dynamic images can be created in this way. However, some aditional code is required. The above example does not, on it's own, display any image or create any link. The 'image src' and 'a href' tags are still required, although with some small additions. The usual code would be: <a href="URL"><img src="image_normal.gif" border=0></a> To use a dynamic image, however, additional elements must be included: <a href="URL" onmouseover="rollon('???'); return true" onmouseout="rolloff('???'); return true"><img name="???" src="image_normal.gif" border=0></a> Note the 'onmouseover' element. It is this that tells the browser to look to the Javascript shown above. It tells the browser to look to the ???on and ???off elements of the Javascript, and load the images associated with these code elements
over the image defined in the 'img' tag. In addition, it is important that the name ??? is used within the 'img src' tag as well as the 'a href' tag. To do this, the code 'name=' must be used. By naming the image, you link it to the Javascript code that also uses the ??? name to define which actions should be carried out. Such dynamic images would appear like so: ![]() Any image can be used in this way. Try it and see! |
Last updated: Monday, 10th May 1999 | [ back | five standing | hypertext theory | the team | links ] |