AlfieWebDevTips Homefor new and experienced developers
[Home Home] [Web Development Web Development ] [Code Generators Code Generators ] [Resources Resources ] [Contact Us Contact ] |WebDevTips Privacy Privacy |
Print This Page

You are here : Home - Web Development - Javascript - A useful link tag

A useful link tag



One tag that is surprisingly under used is the <link> tag. Its primary use appears to be for linking to stylesheets but did you know that you can use it for additional links to other documents on your site?

If you did know that, then you will probably also know that those links don't appear in the major browsers. This is one of the reasons they are over looked - well there are benefits to using the <link> tags.

You get to add extra links that most search engines like. Your <link> links are visible and usable in browsers such as Lynx and browsers designed to cater for users with disabilities.

So, if those links could be visible and placed wherever you wanted then the chances are you would make use of them. Well now you can.

Here my link tag links.

Here is the code for my link tags.

<link rel="home" href="/index.shtml" title="Home Page">         
<link rel="contents" href="/webdevtips/siteindex.shtml" title="Site Map"> 
<link rel="author" href="/webdevtips/about/index.shtml" title="About"> 
<link rel="copyright" href="/webdevtips/copyright.shtml" title="Copyright"> 
<link rel="search" href="/webdevtips/wdt_search.shtml" title="Search This Site">

This makes the link tag useful and worth adding to your site, Personally, Ithink if they had been made more useful in the past then I think people would be using them all the time - it is a very useful tag. So how do you use it?

Firstly create your link tags and place them in the head of your document.

Also in the head - place this script.

<script language="JavaScript1.2"> 
<!-- 
function get_link_tags() { 
linktag = document.getElementsByTagName('link'); 
var msg=""; 
for (var i=0;i < linktag.length; i++) 

    if( linktag[i].rel != "stylesheet"){ 
    msg+= "[<a href='" + linktag[i].href + "' title='"+ linktag[i].rel + "'>" + linktag[i].title + "</a>]\n"; 
    } 

document.getElementById("linktags").innerHTML=msg; 

//-->
 
</script>

Place the following where you want the links to appear.

<div id="linktags" style="background:#e7e7e7;color:black;" align="center"> </div>

Finally call the Javascript from onload.

<body onLoad="get_link_tags();">

So there you have it, easy to use additional links for your site that are useful for everyone. So start using the link tag now - you won't regret it :)




Why not discuss this article in our forum?
08-Mar-2003




Google
 

[back to top of page]   

[labelled with icra -  - this link will open in a new window] [RSS Content]

[Copyright © WebDevTips]