To find the scrolled portion of a screen in legancy browsers you could usually write:
var scrollAmount = (document.layers) ? window.pageYOffset : document.body.scrollTop;
e.g. scrollAmount would contain the value equal to the amount of pixels that the Screen had been scrolled manually by the user using the scroll bars.
How can you using DOM determine this scrolled pixel amount ?
I could image that IE6 is still supporting document.body.scrollTop, but how would you be able to arrive at this using DOM syntax,
or atleast.. how do I find it in NS6 ?
The W3C DOM doesn't talk much about scrolling. Just a "scroll" event, and accessing CSS properties which control scrolling.
The NS6 way is still the NS4 way, window.pageYOffset
It is your detection that is flawed, easy solution:
var scrollAmount = window.pageYOffset ? window.pageYOffset : document.body.scrollTop;
If you going to use object detection in isolation like this, you should at least check for the property you're going to use, and not make assumptions.
Also, when IE6 is in CSS1Compat mode, it is document.documentElement.scrollTop, which means you're going to need something more like:
var scrollAmount = window.pageYOffset ? window.pageYOffset : document[(document.compatMode == 'CSS1Compat') ? 'documentElement' : 'body'].scrollTop;
And that is pretending there are no other browsers other than IE or NS.
Thanks for the explanation..
can I ask.. what is compat mode ??
when would a browser be in compact mode ??
is that something the programmer of the webpage decides based on the page declaration or is that a feature which the user can active in the browser ? (the first mentioned right ??)
I did test pageYOffset in NS6 (atleast the NS6.2 I have) but I could not get it to give any results. ..
meantime -- >
I (finally) managed to find my "danny goodman's object quick reference sheet" and found window.scrollX and window.scrollY defined for NS6.
Thank you for taking time to answer my question.. would be very interested in learning more about the compat mode..
window.pageYOffset works for me in a recent build off of the Mozilla 1.1 branch.
(Netscape 6.2 is based off of... Mozilla 0.94? And NS7 PR is off of a 1.0 branch build)
Anyway, the latest browsers have (arguably) done a bad thing, and that is implement different rendering depending on the dcotype. This is commonly known as doctype sniffing, and is done to preserve backwards compatibility.
IE5.X for Windows was notorious for its CSS box model, which was horrendously misinterpretted, causing much grief for anybody trying to write compliant CSS.
IE6 does its best to fix it, but since so many sites are dependant on IE5.X's broken box model, Internet Explorer willl switch rendering depending on the doctype. No doctype, or HTML doctypes will make document.compatMode == "BackCompat", which essentially means implement the broken box model. XHTML doctypes, and generic XML w/ a CSS stylesheet should make document.compatMode == "CSS1Compat".
Mozilla/Netscape does the same thing essentially. Quirks mode is triggered by HTML doctypes, or no doctype. This is to emulate many popular browser quirks of IE's and NS4's to preserve compatibility.
XHTML 1.0 transitional fires "almost standards mode" which is meant to preserve compatibility with a line-height bug found in all other browsers except for Mozilla. Almost standards mode makes Mozilla exhibit this bug to not break many table-based layouts. Finally, standards-compliant mode fires when the content is served as something not text/html, such as application/xhtml+xml, text/xml, etc. It also fires on text/html when the doctype is XHTML 1.0 Strict or higher.
09-05-2002, 08:07 AM
"or atleast.. how do I find it in NS6 ? "
Well, JKD is right in that Netscape does respond to window.pageXOffset and window.pageYOffset
but it also responds to window.scrollX and window.scrollY
or, version 6.1 does, at any rate...