...

View Full Version : body onload to anchor?



canadianjameson
10-12-2004, 05: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

Mhtml
10-12-2004, 05: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-


location='#top';


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

gohankid77
10-12-2004, 06: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.

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

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

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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum