单击超链接时,Safari 会忽略/删除锚点(或“主题标签")吗? [英] Safari ignoring/removing anchors (or "hashtags") when clicking hyperlinks?
问题描述
我需要将一页指向另一页,然后滚动到特定部分.在 Chrome 和 Firefox 中,使用像 www.example.com#section1
这样的 URL 可以解决问题.(#section1 可以是锚点或元素的 id).
I need to point one page to another and then scroll to a particular section. In Chrome and Firefox, using an URL like www.example.com#section1
does the trick. (#section1 can be an anchor or an element's id).
但是,在 Safari 中,当我单击链接时,哈希值会消失.
However, in Safari, the hash disappears when I click the link.
为什么会这样?是否可以在 Safari 上执行此操作?如果没有,我该如何解决这个问题?
Why is this happening? Is it possible to do it on Safari? If not, how can I get around this problem?
推荐答案
当使用指向其他页面内部部分的超链接时,您必须记住在主题标签前添加斜杠 (/) 以实现跨浏览器兼容性.
When using hyperlinks that point to inside sections on other pages you must remember to add a slash (/) before the hashtag for cross browser compatibility.
例如:www.example.com/#item-1
做 www.example.com#item-1
并不是所有浏览器都接受(显然 Chrome 和 Firefox 是这样)
doing www.example.com#item-1
isn't accepted by all browsers (apparently by Chrome and Firefox it is)
这篇关于单击超链接时,Safari 会忽略/删除锚点(或“主题标签")吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!