Click to See Complete Forum and Search --> : onload goto anchor - how? - sorry for such a simple question!!


rolandscriven
11-22-2003, 12:47 PM
hey guys and gals, i'm sorry im still a bit of a thicko when it comes to javascript but i would really appreciate any help..

what it is is i want to have my page go to a named html anchor onload - something like this

onload goto anchor "#here"

it should be simple - come on peeps - it feels good to help! especially knowing your knowledge is vastly superior to mine..

thanks in advance..

Jupac
11-22-2003, 01:44 PM
umm here is my summer school homework it use <a name
but it dosnt validate HEHE funny story got a 50/50

rolandscriven
11-22-2003, 02:16 PM
dont know if that really solves my problem.. i want it to jump to the anchor when the page loads and not when you click on a link which is easy..

any idea..?

Jish
11-22-2003, 03:00 PM
first add this to the <body> tag of your html page:

<body onload="goToAnchor();">

This will call the function goToAnchor when the page loads. Next you will need to include the function goToAnchor.

<script type="text/javascript">

function goToAnchor() {
location.href = "myPage.html#myAnchor";
}

</script>

Change myPage.html and #myAnchor to your needs. Then all you need is the anchor that you want it to jump to, when the page is loaded.

<a name="myAnchor"></a>

rolandscriven
11-23-2003, 10:51 AM
thanks thats just what i needed - turns out i was doing it okay already - just that i had the right script below some others and it wasnt working for that reason! - if there was some kind of logic to these things it would be cool!