View Full Version : body onload to anchor?

10-12-2004, 06:41 AM
this question should be simple enough to answer.

i have this link

<a href="javascript:history.back()">Back</a>

on the page that the user is going back to, i want it to go back to a specific anchor (or to the top of the page.... the anchor is at the top :D)
- also the user can only get to the page with the <a href="javascript:history.back()"... link on it from one place.

point being, how do i get the page to load to at a specific anchor?

knowing that the page this link takes them to has an anchor called "top"
do i do:

<a href="javascript:history.back()#top">Back</a>

or do i put something on the page that the page being loaded like

<body onload="#top">

lemme know :P

10-12-2004, 06:57 AM
Well you could always do-

<body onload="window.scrollTo(0,0)">

I'm not sure if just #top will work in onload, perhaps you might need-


Of course you're using id's for the anchor aren't you ;)..

10-12-2004, 07:55 AM
I'm not a JS guru by any means (I know random JS stuff without a clue about how to implement most stuff).

Will just "location='top'" work?

Maybe onload="window.location=window.location + '#top'" ?

Just make sure you have an ID'd or named (depending on what DTD you are using) anchor with a value of "top" at the top of the page. Actually, I can't remember if it needs to be on an anchor. It doesn't need to be an anchor in XHTML, but it might in HTML.

10-12-2004, 07:58 AM
ummm, that's essentially what I said lol .. :rolleyes:

10-12-2004, 08:03 AM
Okay. I was just "putting in my two cents". As I said, I'm no JS guru. :p

10-12-2004, 08:06 AM
Haha fair enough..

10-12-2004, 01:25 PM
i used the onload scrollto(0,0) and it works great, thanks.