[英]Anchor tags not working in Google Chrome (when linking to separate webpage)
我对 html、javscript 和 css 有点陌生,所以对于任何明显的无知,我提前道歉。 我正在使用锚标记,以便当用户单击此链接时,它将跳转到另一个网页上的特定 div:
索引.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。
我研究了使用各种 scroll() 函数的 javascript 线程 - 但它们在链接到同一网页上的某个位置时似乎都有效。 当锚点位于不同页面时,我无法找到解决方法。
更新我还注意到这似乎是随机 Chrome 插件的错误 - 与所有插件禁用一样,锚标签工作得很好。 但是,我不能完全期望网站的所有访问者都禁用所有插件。
您实际上需要添加一个name
属性包含 hash 字符串的锚元素,该元素可能为空。 用这个:
<a name="contactForm"></a>
<div class=contact id="contactForm">
...your code
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.