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.
Post Reply
sangnandar
User
Posts: 980

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

Post 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.


arbei
User
Posts: 9286

Post 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.


Post Reply