Ticket #10101 (closed bug: invalid)
scrollTop in iFrame always returns 0
| Reported by: | anonymous | Owned by: | anonymous |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | offset | Version: | 1.6 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Using $(window).scrollTop() in iFrame always returns 0.
To reproduce, load an iFrame from a secondary page. In the iFrame page, specify a scroll event that uses $(window).scrollTop(). You'll notice it always returns 0.
Using document.documentElement.scrollTop or document.body.scrollTop returns the correct value.
Change History
comment:2 Changed 21 months ago by rwaldron
- Owner set to anonymous
- Status changed from new to pending
- Component changed from unfiled to offset
Try this:
$("body").scrollTop()
comment:3 Changed 21 months ago by trac-o-bot
- Status changed from pending to closed
- Resolution set to invalid
Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!
comment:4 Changed 10 months ago by amazingant
I can confirm this still happens with jQuery 1.7.2 with IE 8, and using $("body").scrollTop() also provides a zero regardless of actual scroll position.
comment:5 Changed 10 months ago by dmethvin
Why is it that nobody can produce a test case?
jsFiddle runs its test in an iframe.
worksforme in IE8, so please provide one that doesn't.
comment:6 Changed 10 months ago by amazingant
At the time, I didn't produce a test case because I was busy fixing the issue and moving on to the rest of my work. At this point, partly because some other change I made to my HTML appears to have fixed it with $(window).scrollTop(), although $("body").scrollTop() remains an issue, and partly because jsfiddle doesn't like it when I try to put frames inside of its frames, making it difficult to reproduce the problem there.
As far as with $("body").scrollTop(), I posted an example as a gist on GitHub here:
https://gist.github.com/3137546
This gives me correct values for $("body").scrollTop() in Chrome 20.0 and Safari 5.1.7, zero in IE 8; I don't have access to firefox at the moment. If I can figure out how I had the issue with $(window).scrollTop(), I'll post a second gist for it.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

I forgot to specify that this problem only occurs in IE.