View Full Version : making a link active on page load

03-29-2005, 09:50 PM
Hi. Can anyone tell me how to make a link active on page loading? I tried this:


but that serves only to make the link permanently active even when others are clicked. I really want the link state to be made active rather than emulate by changing the color of it. But i know not how to do it. Can anyone help?

04-02-2005, 09:08 AM
Well in IE it is easy. Just give your link a unique id like so:
<a id="act" href="some.html">Some Link</a>and in your body tag do this:
<body onload="document.getElementById('act').focus()">but, it gets a little more complicated in NS and FF. Modify your link tag to look like this:
<a id="act" href="some.html" onfocus="this.style.color='red'" onblur="this.style.color=''">Some Link</a>and use the same body onload thing. This will work OK in IE as well.

04-02-2005, 02:19 PM
Thanks, that worked a treat

04-02-2005, 04:59 PM
You're welcome. For a little more backward compatibility and graceful degrading on unsupportive browsers try:
<title>Activate Link Onload Demo</title>
<script type="text/JavaScript">
function activate(link){
else if (document.all)
<body onload="activate('act');">
<a href="some.html">Some Link</a><br>
<a href="another.htm">Another Link</a><br>
<a href="important.htm" id="act" onfocus="this.style.color='red'" onblur="this.style.color=''";>Active Onload Link</a>