views:

579

answers:

3

window.scrollMaxY can be set via that property in IE and older versions of Firefox, but when trying in FF3 it says "Cannot set this property as it only has a getter".

What is my alternative?

EDIT:

The reason why I'm asking is that I'm fixing some very horrible JS written by someone else, it has a function to keep a div centered on the page while scrolling, and has this line:

// Fixes Firefox incrementing page height while scrolling
window.scrollMaxY = scrollMaxY

Obviously this doesn't work, but the main issue is that when the page is scrolled, it grows in length.

A: 

window.scrollMaxY can be set via that property in IE and older versions of Firefox

I don't see that this exists in IE at all.

If i try to modify it in FF3 before reading its value, then i am able to do so, although changing it has no visible effects.

If i assign a value to it prior to accessing its value, i'm able to do so. Once i've successfully assigned a value to it, i can query and modify its value as much as i like, though the browser will no longer update it to reflect the actual scroll limit of the window - this behavior would appear to exist for compatibility with code that might use this variable name in other browsers, not expecting it to be pre-defined.

What would you expect modifying it to do?

(testing in IE6 / FF3, answer revised to note pre-query vs post-query behavior)

Shog9
A: 

Why would you want to set it anyway? This property is automatically computed by the browser and contains the maximum vertical or horizontal scroll position possible.

To scroll the window, you use window.scroll(x, y). When calling window.scroll(0, window.scrollMaxY), for example, the window is scrolled to the bottom of the page.

Simon Lehmann
+1  A: 

Sounds like what you are looking for is different CSS. Instead of trying to bend the browser to fit the HTML, it would be easier to find a better solution for the actual problem; keeping the div in place.

To position elements relative to the window use position: fixed;

My guess is that the code you are looking at was originally a workaround for the lack of support for fixed positioning (IE6 doesn't support it).

Borgar