Forum Moderators: open

Message Too Old, No Replies

How to make browser automatically scroll down

after clicking a link far down on the page

         

mgm_03

6:31 pm on Jul 1, 2005 (gmt 0)

10+ Year Member




Let's say I'm on a web page and have scrolled down to some content far down on the page. There, I click a link that sends a server request for data to be returned to that same location on the page.

Is it possible to have the browser window automatically scroll down to where I was when I clicked the link?

I think I have seen this on ebay and probably elsewhere but cannot recall those sites.

Any advice is appreciated. TIA.

moltar

7:02 pm on Jul 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to use on-page anchors. For example:

<a href="/some/page.html#far_down" name="far_down" id="far_down"> 
This is far down the page
</a>

So there are two parts to this.

First you need to identify a location on the page where you want to take the visitor. You can do it with <a name="" id=""> clause. Or you can just set an id="" attribute to any HTML element on the page.

The second part is the link itseld. You want to add the anchor name to the end of the page name. E.g. page.html#far_down.

mgm_03

7:28 pm on Jul 1, 2005 (gmt 0)

10+ Year Member



Thanks for the quick reply. I'm using php/mysql for an FAQ area and the links will look like this:

<a href="?catID=003&fid=00047" class="question">What is Proof?</a>

Does your suggestion still apply in this case?

Thanks

mgm_03

7:33 pm on Jul 1, 2005 (gmt 0)

10+ Year Member



...I forgot to add that when the user clicks on the question, the answer will appear directly beneath it. The longer the list of questions, the more auto-scrolling is needed.

I could have implemented this using just a little bit of javascript to control the answer visibility. However, we want to track which questions are being clicked, hence the need for php/mysql