浏览器后退按钮不适用于锚链接

编程入门 行业动态 更新时间:2024-10-21 11:54:21
本文介绍了浏览器后退按钮不适用于锚链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我页面的页脚中,有一些链接使用锚标记指向同一页面上不同部分的链接(在页面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属性标记的多个部分,该页面可以由带有 #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.

更多推荐

浏览器后退按钮不适用于锚链接

本文发布于:2023-11-23 14:02:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621698.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:锚链   按钮   不适用于   浏览器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!