页面在Internet Explorer中刷新时自动向下滚动

页面在Internet Explorer中刷新时自动向下滚动

问题描述:

Internet Explorer在页面刷新时自动向下滚动页面,并将焦点放在刷新前的位置。我曾尝试下面的东西来覆盖此行为,但毫无效果:页面在Internet Explorer中刷新时自动向下滚动

$(window).on('beforeunload', function() { 
    $(window).scrollTop(0); 
}); // option 1 

window.onload = function() { 
    jQuery('body').css({'overflow': 'auto', 'position': 'static'}); 
    window.scrollTo(0, 0); 
}; // options 2 

我在页面顶部的“H1”的标签,我试图用这个代码把焦点是元素太多:

$(document).ready(function() { 
      document.getElementById('pageHeader').focus(); 
     }); // Option 3 

以上所有的代码执行BUT后,所有这些IE抛出焦点,我刷新之前。我的问题是我使用屏幕阅读器来阅读页面内容,所以我希望页面滚动到每个页面上的TOP刷新。在Chrome上一切正常。请帮帮我。

+0

什么是你的问题陈述?当页面刷新时,你想滚动到顶部吗? –

+0

@PraneshRavi是的。我希望我的页面在刷新时向上滚动。我也更新了我的问题。 – rishi

这应该在所有的浏览器...

$(window).on('load', function() { 
    $(window).scrollTop(0); 
}); 
+0

这应该是被接受的答案。 – catbadger