网址中的HTML锚点无法在Chrome中使用

时间:2016-05-10 13:31:07

标签: html google-chrome anchor

我一直把头发拉到一个小东西上:https://numa.co/about/#corporate-innovation

此网址没有转到正确的锚点,仅限Chrome浏览器,我无法理解为什么......它适用于我们的开发环境,唯一的区别是我可以看到我们在产品和它的HTTPS中支持Cloudflare。我不知道这会如何产生影响。

非常感谢任何见解:)

4 个答案:

答案 0 :(得分:1)

您有两个具有相同id="corporate-innovation"的元素。浏览器将转到第一个元素。 id对一个元素必须是唯一的。 Check the spec.

答案 1 :(得分:0)

看起来这个名字对我来说是空的。这需要与url片段相同。看看我的检查员http://imgur.com/yy2fjp4

的这个视图

可能需要查看原始HTML,看看是否存在语法问题。图像上的检查员是Mac上的Chrome

我会尝试将HTML更改为更像

<a name="corporate-innovation"></a>     
<h3 style="color:#E50064">Corporate Innovation</h3>
<span style="color:#E50064"><p>NUMA helps corporates innovate in a different way by collaborating with an ecosystem of entrepreneurs and experts. We provide new methodology training, accelerated intrapreneurship projects, and create open innovation programs for large companies and public institutions.</p>
</span>

答案 2 :(得分:0)

这是解决您问题的方法。适用于所有主流浏览器。 将此javascript代码放在锚点所在页面的head部分。

<script>
window.onload = function() {
	if(window.location.hash) {
	   elmnt = document.getElementById(window.location.hash.substring(1));
           elmnt.scrollIntoView(true);
	}
}
</script>

答案 3 :(得分:-3)

我为电子邮件使用了很多锚点,我发现最好的方法就是使用这样的网址。

https://numa.co/about/?anchor=corporate-innovation

这会将您带到网站和页面,然后自动转到页面上的那个锚点

让我知道这是否有帮助:D