20

As far as I know, pageXOffset/pageYOffset properties were already available since Netscape 4 era.
And it seems scrollX/scrollY were introduced circa Netscape 6.

Alternative question:

Q2. Is there a browser which implements scrollX/scrollY but doesn't support pageXOffset/pageYOffset?

I will add a third question because no one was able to answer the previous ones:

Q3. scrollX/scrollY was added to the latest editor's draft of the CCSOM and the working draft only got pageXOffset/pageYOffset, why are they keeping both attributes?

Knu
  • 14,012
  • 5
  • 54
  • 86
  • MDN states the following: The `pageXOffset` property is an alias for the scrollX property: `window.pageXOffset == window.scrollX; // always true`. This doesn’t answer why, but at least it suggests that the answer to Q2 is no. – Manngo Feb 04 '17 at 02:24

4 Answers4

7

Is there a browser which implements scrollY/X but doesn't support pageY/XOffset

I guess what you want to know is whether you can fully trust pageY/XOffset and leave scrollY/X out of the game. The answer is yes. pageY/XOffset is working in Firefox, Chrome, Opera, and IE 9!

I can't test scrollX/Y on IE9 currently, but it is not listed on MSDN properties so there is a good chance it answers your question. So there may be browsers implementing pageY/XOffset but not scrollY/X.

Why were window.scrollY and window.scrollX introduced?

As scrollY is only an alias, I'm sure it is only for better readability.

gblazex
  • 45,901
  • 12
  • 91
  • 86
  • 2
    Nope, according to the link you provided, pageY/XOffset is an alias to scrollX/Y https://developer.mozilla.org/en/DOM/window.scrollY – Michael Sep 23 '14 at 15:40
  • 1
    `For cross-browser compatibility, use window.pageYOffset instead of window.scrollY.` – Dan Dascalescu Jul 21 '15 at 08:01
2

Everything about it. As you can see pageXOffset isn't supported by Internet Explorer 8 and below. In IE8 (and lower) you should use scrollLeft / scrollTop of document.body or document.documentElement depending what works (just like it is implemented in jQuery).

You can check it here: http://jsfiddle.net/8RFAn/1/

And I don't know why window.scrollX/Y were introduced, for me these properties looks like pageX/YOffset in terms of effect and browsers in which are implemented.

pepkin88
  • 2,658
  • 17
  • 18
-1

As pepkin88 said, pageXOffset (and all pageXY values) are not supported in earlier versions of Internet Explorer. Most of the properties used to locate objects and calculate mouse positions are not part of the W3C standards. From what I remember reading, most of the properties are Microsoft's invention. So when you speak of scrollX and scrollY, you are speaking of the original pageXYOffset values. When standard compliant browsers came along that supported the pageXY properties (not part of Microsoft's model), they decided it would be too confusing to stick with the scrollXY values. So, they switched to a much more logical (in their opinion) version: pageOffset.

In my opinion, I find the scrollXY values more intuitive to use. I will usually have to pause and think, every time I try to decide between screenX, pageX, or clientX. I think they could have come up with more intuitive names for each of the properties. Anyways, none of them are really W3C standard, so I guess conventions aren't really that important in this realm of JavaScript. I'm very glad Microsoft invented them though, because they turn out to be very useful.

Azmisov
  • 4,400
  • 4
  • 40
  • 63
-1

I will try to answer using my common sense, nothing official so sorry if that's not what you meant in your question.

window.scrollY and window.scrollX are used to decide how much the website user has scrolled vertically or horizontally.

This is useful for example in scripts that can only detect the "absolute" position of something in the document and need to place something else on top/beside of it, so using the scrollX and scrollY values they can calculate the proper position.

So probably when demand raised for dynamic scripts like custom tooltip, the people responsible for the JavaScript "framework" answered the call and introduced those properties.

Like I said, not official answer, your Googling will be as good as mine to find such answer. :)

Shadow The Vaccinated Wizard
  • 62,584
  • 26
  • 129
  • 194