问题描述
我遇到了与Chrome之间的外部链接问题。在我的网站上,当我点击一个链接时,我想从一个子页面回到主页面的特定部分。我使用了一个简单的#锚来实现这一点,就像我以前一直做的那样......除了chrome之外,它在所有浏览器中都能正常工作。点击Chrome中的链接时,我被重定向到主页面的顶部。 (但我可以看到显示在网址栏中的#锚点)与所有其他浏览器此操作工作正常。这是由于铬的错误?如果是这样,有人可以提出一个解决办法吗?这是我得到的代码。在主页上:< div id =page-anchor>< / div>
I am having issue with external anchor links with Chrome. On my website, I want to navigate back from a subpage to a specific section of the main page when clicking a link. I used a simple # anchor to achieve this like I always did in the past...It works fine in all browsers except for chrome. When clicking the link in chrome, I am redirected to the top of the main page. (But I can see the #anchor showing in the url bar) With all other browser this action works fine. Is this due to a bug with chrome? If so, can someone suggest a work around? Here are the codes I got. On main page: <div id="page-anchor"></div>
子页面:< div id =go_back>< p>< a id =backhref =../ index.html#page-anchortarget =_ self >返回投资组合< / a>< / p>< / div>
推荐答案
我有同样的问题。尝试此解决方法
I have the same issue. Try this workaround
var hash = window.location.hash;
if ($(hash).length) {
$('html, body').stop().animate({
scrollTop: $(hash).offset().top
}, 1000);
}
这篇关于外部锚点链接在Chrome中无法使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!