Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#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:
Blocked by: Blocking:

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 (8)

comment:1 Changed 8 years ago by anonymous

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

comment:2 Changed 8 years ago by Rick Waldron

Component: unfiledoffset
Owner: set to anonymous
Status: newpending

Try this:

$("body").scrollTop()

comment:3 Changed 8 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

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 7 years 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 7 years ago by dmethvin

Why is it that nobody can produce a test case?

http://jsfiddle.net/eDJYm/

jsFiddle runs its test in an iframe.

worksforme in IE8, so please provide one that doesn't.

comment:6 Changed 7 years 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.

comment:7 Changed 5 years ago by anonymous

I'm seeing this problem in Chrome 32.0.1700.77 on Mac OSX. The suggested solution [$("body").scrollTop()] also yields zero.

comment:8 in reply to:  7 Changed 5 years ago by anonymous

Please disregard this. I forgot that we are using an old version of jQuery (viz., v. 1.7.2).

Note: See TracTickets for help on using tickets.