My product view is suddenly loading at the bottom of the page requiring visitors to scroll up. This is affecting all of my products.
What code I can use to force the page to the top upon load so that visitors are not required to scroll up?
most likely you have a form in the footer that is set on autofocus.
This happens when you created a from js object like this:
var someForm = new VarienForm('some-id', true);
the second parameter means firstFieldFocus
. So if you set it to true then the first field in the form will be autofocused when loading the page.
There is no need for js workarounds. Just make the second param false
;
My money is on a newsletter form
My solution to this was simply going to opcheckout_rwd.js
and added this code
Find this section:
this.currentStep = section;
var sectionElement = $('opc-' + section);
sectionElement.addClassName('allow');
this.accordion.openSection('opc-' + section);
Added this line:
$j('html,body').animate({scrollTop: $j('#checkoutSteps').offset().top}, 15);
Scroll viewport to top of checkout steps for smaller viewports
if (Modernizr.mq('(max-width: ' + bp.xsmall + 'px)')) {
$j('html,body').animate({scrollTop: $j('#checkoutSteps').offset().top}, 800);
}
This can be resolved with java script. You need to add the following code at the bottom of view.phtml:
<script type="text/javascript">
window.onload= function(){
parent.window.scrollTo(0,0);
}
</script>
This will automatically scroll the visitors window to the top of the page.