I have inherited maintenance of a mess of a project. There's a particular set of (rather tall) pages that scroll way down the page on every page load, and eventually it occurred to me that it's because a particular field is in focus after the page is loaded, and this field (of course?) was scrolled into view.

The thing is, nowhere (relevant) in the entire code base can I find the (partial) words scroll, focus, select, or activat, so I really can't figure out WHY this one field is given focus!

Setting autofocus on the first form field does not change the behaviour (although this may possibly be due to timing of scripts). I can use window.onload with myFirstInputElement.focus(), but this scrolls that field to the top of the view, and still does not show the top of the page. Trying to use .scrollTo() or .scrollTop() has no effect.

What else might I be overlooking?

Alas, this is incredibly complicated code, with template generators and whatnot, so it is not possible to show you a condensed, minimal example exhibiting this behaviour (if I could, I could probably spot the problem myself).

  • Does your site use third party JavaScript? It could be something outside of the code base that is still used in the page. Aug 17 '20 at 12:12
  • @StephenOstermiller, as far as I can see we only use locally stored scripts, including a local version of jQuery (v1.02).
    – KlaymenDK
    Aug 17 '20 at 12:16
  • try to inspect jQuery plugins, if any. Try to inspect all javascipts, which come with template generator. Try to inspect page loading commenting javascripts out one by one.
    – Evgeniy
    Aug 24 '20 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.