user557419
user557419

Reputation:

How to make page autoscroll to DIV onload

I have a quicklaunch (bookmark list if you'd like) which will send the user to different pages with lots of text. So I want them to be sent to the specific paragraph.

Is it possible to make a page autoscroll to a specific DIV onload and how?
I'll live without the animation. If it can just go to it directly that'll make my day. Like when you have an <a href="#SomeId"> tag and when you click that anchor it sends you to that div.

Edit: If the user bookmarks the top paragraph, an ID isn't saved for the link. So in that case I just want it to go to the where the content div starts. How is this possible?

Upvotes: 3

Views: 3085

Answers (1)

Purag
Purag

Reputation: 17061

Try this:

window.location.hash = "myDiv";

This will change the hash to myDiv (and scroll to the element whose id attribute is equal to the hash).

Example.

Upvotes: 2

Related Questions