views:

33

answers:

2

I know that in Javascript document.location.href = "#my_id" tells the browser to display the same page starting from element with id="my_id". In this case, the address that appears in the address bar is in the following format: my_page_address#my_id

Is this the only method to refer to a specific place on a page ? I'm looking for a method that will not show my_id in the address bar.

+4  A: 

Most browsers implement the scrollIntoView method (MDC, MSDN) on elements. That works on IE6 and up (at least), Firefox and other Gecko-based browsers, Chrome and other WebKit-based browsers, Opera, etc.

scrollIntoView example using an element retrieved by ID:

document.getElementById("my_id").scrollIntoView();

Of course, this requires that Javascript be enabled (I'm assuming this is okay because of the Javascript tag on the question :-) ).

You can also scroll to specific coordinates on the page using window.scrollTo.

T.J. Crowder
+2  A: 

Have you tried document.getElementbyId("my_id").scrollIntoView()?

RoToRa
Great ! This is what I was looking for !
Misha Moroshko