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

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.

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

Postby sangnandar » Mon Jan 08, 2018 2:49 pm

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.
sangnandar
 
Posts: 296
Joined: Mon Sep 19, 2016 2:04 am

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

Postby arbei » Wed Jan 10, 2018 12:07 pm

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.
arbei
 
Posts: 1499
Joined: Wed Sep 09, 2015 10:13 am


Return to General Discussion (PHPMaker)