[Project_owners] How to obtain the scrollbar positions of a webpage?

Jaap Haitsma jaap at haitsma.org
Sun Aug 1 23:30:54 EDT 2004

Christopher Ottley wrote:
> Jaap Haitsma wrote:
>> Anybody knows how I should get the scrollbar position of the mainwindow?
> If you have the browser object for the tab you want to modify, you can 
> save and set
>   aBrowser.contentWindow.scrollX
> and
>   aBrowser.contentWindow.scrollY
> where aBrowser is the variable holding your browser object.

I almost got it working . Obtaining the scroll postions works but I 
don't seem to be able to set them. I'm trying to use the 
aBrowser.contentWindow.scrollTo(x,y) method. Something weird is going on
See comments in code below. (log is just a function that dumps the 
variables to the console)

curScrollX = tab.contentWindow.scrollX;
curScrollY = tab.contentWindow.scrollY;
//Let's say the position is curScrollX=100, curScrollY=100

tab.webNavigation.loadURI(tab.reloadEveryURL, loadFlags, null, 
entry.postData, null);
// This loads a page and we see the top of that page.

log(tab.contentWindow.scrollX + ',' +tab.contentWindow.scrollY);
// Still prints (100,100). I would expect (0,0)
log(curScrollX + ',' +curScrollY);
// Prints of course (100,100)
tab.contentWindow.scrollTo(curScrollX, curScrollY);
// Does not seem to scroll the window. Nothing happens
log(tab.contentWindow.scrollX + ',' +tab.contentWindow.scrollY);
// Still prints (100,100)

What's going wrong here?? I don't get it


More information about the Project_owners mailing list