Forum Moderators: open

Message Too Old, No Replies

horizontal scrollbar position

         

maxcohen

4:08 pm on Jul 1, 2005 (gmt 0)

10+ Year Member



Hi, I'm new to javascript, but got some java knowledge. Can anyone tell me how I can set the horizontal scrollbar of a page in the center of the page on load? I've written something that works, but doesn't do ther job.

Thanks in avdance,
max

<html>
<head>
<script type="text/javascript" language="JavaScript">

function scroll() {
var a = window.document.body.clientWidth;
a /= 2;
window.scrollTo(a, 0)
}

</SCRIPT>
<BODY ONLOAD="scroll()">

j4mes

11:58 am on Jul 3, 2005 (gmt 0)

10+ Year Member



You could place an anchor in the middle (horizontally) of the page and then redirect to page#anchor onload:

window.location += "#anchor";

maxcohen

8:45 pm on Jul 4, 2005 (gmt 0)

10+ Year Member



I tried it, but it didn't work, since the anchor doesn't direct the position of the horizontal toolbar to the middle, not even if I center my anchor; it only makes the anchor visible.

Thanks anyway.

Anyone more suggestions?