在谷歌浏览器中,锚点标签不工作(当链接到单独的网页时)。

问题描述 投票:0回答:1

我对html、javscript和css有点陌生,所以我为任何明显的无知提前道歉。我使用了一个锚标签,这样当用户点击这个链接时,它就会跳转到另一个网页上的特定div。

index.html:

<div class="notice">
  <h2>If you have any trouble while you're here, please <br>
  <a href="/contact.html#contactForm"> get in touch with me</a> and let me 
        know!</h2>
</div>

联系方式.html:

<div class=contact id="contactForm">

然而,当你点击链接时,Chrome会忽略#,只加载contact.html。但是,当你导航回index.html,然后点击链接时。再次 - 然后,Chrome 决定关注 # 并加载 contact.html#contactForm。

我研究了使用各种滚动()函数的javascript线程--但它们似乎都在链接到同一网页上的地方时工作。当锚点在不同的页面上时,我很难找到一个变通的方法。

更新我还注意到,这似乎是随机Chrome插件的错--因为在禁用所有插件的情况下,锚标签工作得很好。然而,我不能完全指望网站的所有访问者都禁用所有的插件。

javascript html css google-chrome anchor
1个回答
0
投票

实际上,你需要添加一个锚元素,并在锚元素上加上一个 name 属性,这个元素可以是空的。使用这个。

<a name="contactForm"></a>
<div class=contact id="contactForm">
...your code
© www.soinside.com 2019 - 2024. All rights reserved.