window.top.document.body.scrollTop not working in Chrome or FireFox
Another solution:
(document.documentElement.scrollTop || document.body.scrollTop)
Depending on your browser's current rendering mode, you may need to use document.documentElement.scrollTop
instead of document.body.scrollTop
(and likewise for scrollLeft
).
There's some good background on this problem in an Evolt article by Peter-Paul Koch (of quirksmode.org fame), but it's from 2002 and is a bit dated now.
As others here are suggesting, the easiest way to solve this kind of problem in 2011 is to just use an existing JavaScript framework. jQuery is quite popular (especially among StackOverflow users), but there are many others as well.
If you don't see the need for unecessary third party libraries, you could try:
var scrollTop = (document.documentElement || document.body.parentNode || document.body).scrollTop;
It's hacky, but it's still better than JQuery.
you can use:
window.pageYOffset