在同一位置重新加载页面 [英] Reload page in same position

查看:65
本文介绍了在同一位置重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我想知道在重新加载页面时是否有一种简单的方法可以将页面滚动到先前的位置.例如,我在页面的一半下方有一个公告板.这些公告是分页的,用户可以单击下一步"以查看下一批公告.页面重新加载时出现的问题是其正常行为,即跳转到页面顶部.使用F5重新加载页面时,页面重新加载到相同位置的一个很好的例子.

Hi I wanted to know if there was an easy way to scroll a page to its previous position when it reloads. For example I have a bulletin board half way down my page. The bulletins are paginated and the user can click next to see the next lot of bulletins. The problem when the page reloads it does its normal behaviour of jumping to the top of the page. A good example of the page reloading to the same position is when you reload the page using F5.

我知道很难做到这一点.

I know the hard way to do it.

分页链接就是这样

 index.php?page_num=2&page_scroll=200;

页面加载时,运行一个脚本,该脚本从url中拉出页面滚动并设置

When the page loads run a script which pulls out the page scroll from the url and sets

document.body.ScrollTop==200px.

当然可以访问最后一页的dom,并在重定向之前获取其位置.当您按F5键时,浏览器如何执行?

Surely It is possible to access the dom of the last page and get it's position before it redirected. How does the browser do it when you hit F5?

推荐答案

您可以使用html锚点滚动到页面的一部分:

You can use an html anchor to scroll to part of a page:

index.php?page_num=2#YOURID

或使用您的js进行设置. location.hash

Or set it using your js. location.hash

这篇关于在同一位置重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆