Page 1 of 1

jQuery .focus() caused page to scroll to the top on Chrome

Posted: Mon Jan 08, 2018 2:49 pm
by sangnandar

My setup:
Edit Page, not too long though, but the field I need to focus is located outside visible area.
Startup script:
$('#x_(fieldname)').focus();

These behaviors happen both on fresh load or refresh.

Behavior on FF (latest version):
When the page loads, it automatically scrolls so the focused field is now inside the visible area.

Behavior on Chrome (latest version):
Like FF, but after it scrolls to the field, it scrolls back to the top.

I need Chrome to behave, at least, like FF.

Is there any solution?

Thanks.


Re: jQuery .focus() caused page to scroll to the top on Chro

Posted: Wed Jan 10, 2018 12:07 pm
by arbei

Search "jQuery scroll to element" in Google Search and you can find the example to make the page scroll to specific control.

So use the method after your .focus() function.