Forum Moderators: open

Message Too Old, No Replies

Script to control position "onload"

         

D_Benway

3:39 am on Feb 23, 2008 (gmt 0)

10+ Year Member



I am new to javascript and have a specific event that I would like to occur on the loading of new pages from links within my website.

I would like to know if there is a script that can control the positioning of a new page when it is loaded. For instance, if a link is located at the foot of a page, and a visitor must scroll to the bottom of this page before they can click it—is it possible to have the new page load such that the visitor is at the bottom of the new page?

I am assuming this would have something to do with retrieving the coordinates of the user's location within the page and telling the next page to load at the same coordinates. Is this possible?

daveVk

4:38 am on Feb 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could use javascript to set the scroll position on load, however consider using anchor tags instead.

For example you want to go to foot section of pageB use link <a href="/pageB.html#foot">page B</a>

And in page B at top of foot section

<a name="foot" />

No javascript required, welcome to forum.

D_Benway

6:50 pm on Feb 24, 2008 (gmt 0)

10+ Year Member



Anchor tags are a possibility that did not occur to me. Thanks for the suggestion.

What type of Javascript would control the scroll position?

Thanks again.

daveVk

12:23 am on Feb 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



window.scrollTo(iX, iY)

Is the function to use, thats the easy part, you would need to transit the position information to the new page somehow, as part of url or cookie maybe, and determine the equiv posn on the new page etc.

Much easier and probably better to use anchors.