Has anyone noticed that when you do a "find on this page" in Internet Explorer (7 and 8), which causes the page to scroll down, the onscroll event isn't fired?

I have a situation where I need the onscroll event to be fired under those circumstances. Does anyone know a way of achieving that?

Dani AI

Generated

Good that solved it — this is a common IE gotcha: the built‑in Find can move the viewport without reliably dispatching the page's normal onscroll handler in older IE versions. The most robust fix across IE7/8 and modern browsers is to detect changes to the scroll position yourself (polling) and call your scroll logic when it changes. This avoids relying on an event the browser might not fire.

Example pattern (works in IE7/8):

(function () {
  var lastY = -1;

  function getScrollY() {
    return (typeof window.pageYOffset === 'number') ?
      window.pageYOffset :
      (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop || 0;
  }

  function checkScroll() {
    var y = getScrollY();
    if (y !== lastY) {
      lastY = y;
      onManualScroll(y); // replace with your scroll handler
    }
  }

  var pollInterval = setInterval(checkScroll, 150);

  if (window.addEventListener) {
    window.addEventListener('unload', function () { clearInterval(pollInterval); }, false);
  } else {
    window.attachEvent('onunload', function () { clearInterval(pollInterval); });
  }
})();

Notes: choose 100–250 ms for the interval to balance responsiveness and CPU use; stop polling when not needed (page hidden or on unload). In modern browsers you can listen for selectionchange or use requestAnimationFrame to reduce overhead, but those are not reliable in IE7/8—so keep the polling fallback for widest compatibility.

Fixed it now. No reply needed. Cheers!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.