Forum Moderators: open

Message Too Old, No Replies

Problem with scrollTop and scrollLeft in onload event

         

yoavr

10:57 pm on Jan 27, 2010 (gmt 0)

10+ Year Member



I can't set the scrollTop and scrollLeft in a onload event..
My JS code is something like:

function abc() {
document.getElementById('somediv').scrollTop = document.getElementById('somediv').scrollHeight;
document.getElementById('somediv').scrollLeft = document.getElementById('somediv').scrollWidth;
}

and this function is called in "body onload" event (the "somediv" has scrollbars with overflow:auto; style).
If I change the event from "onload" to some "onclick" event, it's work.

What can I do?

vol7ron

2:05 pm on Jan 28, 2010 (gmt 0)

10+ Year Member



Everything I tried works with that code. I used FF3.6 and IE7.

Perhaps you need to post a stripped-down test HTML page.

Make sure the event isn't being fired before the page has finished loading. You could embed the JS at the bottom of the page, but check the difference between onload and DOMContentLoaded