Bill
Bill

Reputation: 19308

JS prevent scrollTo from called from external js

Is there a way to prevent window.scrollTo, we have a problem with an external library injecting an UI component and then it will scroll to the top of the page, which is terrible for user experience, because you will scroll into this component and page will jump to top of window.

appreciate any great suggestions.

Upvotes: 0

Views: 158

Answers (1)

Yeldar Kurmangaliyev
Yeldar Kurmangaliyev

Reputation: 34234

Answering your question

Is there a way to prevent window.scrollTo

Yes, you can store it in a variable, and override it:

window._scrollTo = window.scrollTo;
window.scrollTo = function() { };

Then, if you need to use scrollTo yourself, you can simply use the moved function:

window._scrollTo(...);

However, it does not sound correct.
You need to find the reason of this problem, and fix it.

Upvotes: 2

Related Questions