Results 1 to 4 of 4

Thread: making a link active on page load

  1. #1
    Join Date
    Mar 2005
    Location
    kent, england
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default making a link active on page load

    Hi. Can anyone tell me how to make a link active on page loading? I tried this:

    document.getElementById("pic1").style.color="#FF0000";

    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?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,069
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Well in IE it is easy. Just give your link a unique id like so:
    HTML Code:
    <a id="act" href="some.html">Some Link</a>
    and in your body tag do this:
    HTML Code:
    <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:
    HTML Code:
    <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.
    Last edited by jscheuer1; 04-02-2005 at 08:41 AM.

  3. #3
    Join Date
    Mar 2005
    Location
    kent, england
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks, that worked a treat

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,069
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    You're welcome. For a little more backward compatibility and graceful degrading on unsupportive browsers try:
    HTML Code:
    <html>
    <head>
    <title>Activate Link Onload Demo</title>
    <script type="text/JavaScript">
    function activate(link){
    if(document.getElementById)
    document.getElementById(link).focus();
    else if (document.all)
    document.all(link).focus();
    }
    </script>
    </head>
    <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>
    </body>
    </html>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •