简体   繁体   English

后退按钮导致滚动到顶部

[英]back button causing scroll to top

I have the following scenario, a user is scrolled some wheres down a search page. 我有以下情况,用户在搜索页面中向下滚动。 They click on an item and after they are done viewing the item they hit the back button. 他们单击一个项目,并在查看完项目后单击“后退”按钮。 The back button brings the user back to their exact location within the search page as it's suppose to. 后退按钮可将用户带回到其在搜索页面中的确切位置。 After a second, the page auto scrolls to the top of the search results. 一秒钟后,页面会自动滚动到搜索结果的顶部。 You can see this behavior in action cardaddy.com/forsale 您可以在action cardaddy.com/forsale中看到此行为

I've spent a couple hours trying to figure this out with no success. 我花了几个小时试图解决这个问题,但没有成功。 I'm not aware of any js causing this issue either. 我也不知道任何js导致此问题。 Please feel free to take a look. 请随时看看。 Any suggestions would be great since this is destroying my ux 任何建议将是巨大的,因为这正在摧毁我的用户体验

I though maybe the forward from my root domain to www.domain.com with godaddy.com may of been the cause, so i changed that behavior around to use amazons name server eliminating the forwarding. 我虽然可能是从我的根域到godaddy.com的www.domain.com的转发,可能是原因,所以我改变了这种行为,使用亚马逊名称服务器消除了转发。 I thought I repaired the issue as it seem repaired on the desktop, but it still seems to happen on mobile. 我以为我已经修复了该问题,因为它似乎已经在台式机上修复了,但是似乎仍然在移动设备上发生。

As far as I know, this behaviour depends on your browser. 据我所知,这种行为取决于您的浏览器。

The back button brings you to the last site you visited and loads this site new. 后退按钮可将您带到您上次访问的站点,并重新加载该站点。 So the effect to stay at the possition is caused by the browser engine. 因此,停留在该位置的效果是由浏览器引擎引起的。

1 way of doing it would be to save the location of the page and restore to that location when back button is clicked on click : var position = $(window).scrollTop(); 一种方法是保存页面的位置,然后在单击click时单击后退按钮,将其恢复到该位置: var position = $(window).scrollTop();

On back button : $(window).scrollTop(position); 在后退按钮上: $(window).scrollTop(position);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM