浏览器后退按钮不适用于锚链接 [英] Browser back button does not work for Anchor links

查看:70
本文介绍了浏览器后退按钮不适用于锚链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我页面的页脚中,有一些链接使用锚标记指向同一页面上不同部分的链接(在页面URL上附加#)。

In the footer of my page there a few links that point to different sections on the same page using anchor tags (# appended to the URL of the page).

这很好,只是浏览器后退按钮不起作用:我无法从导航到锚定页面的位置移回上一页。

This works fine, just the browser back button does not work: I cannot move back to the previous page from where I had navigated to the anchored page.

简单的问题在这里,在锚定页面中浏览几次后是否可以返回上一页?

The simple question here is, is it possible to move back to previous page after navigating in the anchored page a few times? If it is then please could you suggest how?

锚定页面:该页面具有由id属性标记的多个部分,该页面可以由带有<$的URL指向。 c $ c> #anchorId 最后。

Anchored page: the page that has several sections marked by the id attribute that can be pointed to by a URL with #anchorId at the end.

推荐答案

我也遇到了同样的问题,请参阅我的问题锚定链接指向页面部分无法在浏览器上进行刷新,前进和后退

I also faced the same problem see my question anchor links referring to the page sections not working on browser refresh, back and forward

但是我必须按照正常链接的工作方式进行操作,所以我要做的是手动转到

But I had to do it the way normal links work so what I did was I manually go to that section by getting the element from the hash.

$(window).on('hashchange', function () 
{
    var top = $(window.location.hash).offset().top;
    $(window).scrollTop(top);
});

此功能适用于前进和后退按钮。
为了刷新,您还需要执行相同的操作。从哈希中获取元素,然后手动滚动到该元素。

This works for forward and back buttons. And for refresh also you need to do the same thing. Get the element from the hash and scroll to that element manually.

这篇关于浏览器后退按钮不适用于锚链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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