/    Sign up×
Community /Pin to ProfileBookmark

window.onscroll event not firing in IE6

Hi all,
I am writing a routine to be triggered when the page is scrolled, but seem to be having problems with IE6. A sample page is [URL=http://www.users.bigpond.net.au/ggoodacre/basics2%20scroll%20test.html]here[/URL] . The page layout is one of Stu Nicholls, and uses divs to emulate frames, and the scrollbar is actually on one of the divs, not the document – this may be the problem. On the sample page, an alert box pops up as it should in FF but not IE. It seems like the onscroll event is not propagating to the window level in IE – maybe I need to sense the onscroll even on another element?

Any suggestions welcome.

Thanks
Graeme

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@JulianJJun 20.2006 — Because it is the DIV that is scrolling, not the window. You need to attach the event to the content DIV after it has been created, like so:

<body onload="document.getElementById('content').onscroll = e;">

The onscroll event works fine in IE but is kinda broken in Firefox.

Julian
Copy linkTweet thisAlerts:
@CentauriauthorJun 20.2006 — Hey, thanks for that!

I did try the getElementById construct, but only in the same place as the window.onscroll, and it didn't work - didn't think of putting in body onload, though now I can see that the div would probably have to be defined BEFORE setting an action on it...

This does raise the question of event bubbling - I would have thought that a div scroll event would bubble through to the window object, and it appears to do so in Firefox - kind of strange IE didn't accept it when they pioneered event bubbling...???

Anyway, that fixed the problem - thanks again
Copy linkTweet thisAlerts:
@phpnoviceJun 20.2006 — This does raise the question of event bubbling - I would have thought that a div scroll event would bubble through to the window object, and it appears to do so in Firefox - kind of strange IE didn't accept it when they pioneered event bubbling...???[/QUOTE]
Possibly this is because the window doesn't scroll when an embeded element scrolls. Conversely, if you click on an embeded element, then the document was also clicked on -- thus, this event bubbles. So, it seems that events bubble up to the document level -- but not to the window level. Don't know (just being logical). ?
×

Success!

Help @Centauri spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...