我对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>
contact.html:
<div class=contact id="contactForm">
然而,当你点击链接时,Chrome会忽略#,只加载/contact.html。但是,当你导航回/index.html,然后再次点击链接时,Chrome决定关注#并加载/contact.html#contactForm.
我研究过使用各种scroll((函数的javascript线程,但当链接到同一网页上的某个位置时,它们似乎都能工作。当锚在不同的页面上时,我很难找到解决方法。
UPDATE我还注意到,这似乎是随机Chrome插件的错——因为所有插件都被禁用了,所以锚标记工作得很好。然而,我不能指望所有访问该网站的人都禁用所有插件。
您实际上需要添加一个锚元素,该元素具有包含哈希字符串的name
属性,该元素可能为空。使用此:
<a name="contactForm"></a>
<div class=contact id="contactForm">
...your code