How to set scroll on old browsers? Error: Failed to execute 'scrollTo' on 'Window': 2 arguments required, but only 1 present

Viewed 287

I've got a React web app (single page). And sometimes I need to reset or set scroll position between route changes or filter settings.

This is the code I'm using. It works fine on every modern browser.

window.scrollTo({top: totalDistance});  // EXAMPLE 1
window.scrollTo({ top: 0 });            // EXAMPLE 2

I keep a log from my client errors, and I've been getting these for older browsers:

"Failed to execute 'scrollTo' on 'Window': 2 arguments required, but only 1 present."

These are the browsers that are getting this:

Chrome 49.0.2623.112 - Windows Vista
Chrome 49.0.2623.112 - Mac OS 10.8.5
Chrome 53.0.2785.124 - Android 6.0.1

How can I write the scrollTo() function safely for those browsers? Right now I'm just wrapping it in a try-catch.

Reference: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTo

0 Answers
Related