【问题标题】:Anchor tag doesn't work in second level pages锚标记在二级页面中不起作用
【发布时间】:2020-05-15 17:28:17
【问题描述】:

我有一个包含此内容的菜单:

<div class="menu">
    <ol>
        <li data-target="home" ><a href="#home">hello</a></li>
        <li data-target="contact" ><a href="#contact">Contact</a></li>
        <li data-target="policy_privacy" ><a href="https://somesite.com/privacy_policy">Privacy</a></li>
    </ol>
</div>

当我在home 页面上时,锚点工作良好(#home#contact),但如果我在privacy_policy 页面上,并尝试转到主页,则没有任何反应。如果我不在主页(包含锚点)中,如何以某种方式检测并将用户重定向到主页?

【问题讨论】:

    标签: html anchor anchor-scroll


    【解决方案1】:

    如果为privacy_policy页面添加单独的标记,您可以在锚标记中添加主页的链接似乎并不容易,那么您应该 尝试这样的事情。

    if (window.location.href.includes("privacy_policy")) {
        document.querySelector('#home').href = "https://somesite.com";
    }
    

    【讨论】:

      猜你喜欢
      • 2019-04-19
      • 1970-01-01
      • 2013-11-08
      • 2013-12-02
      • 2013-07-07
      • 2013-06-12
      • 1970-01-01
      • 1970-01-01
      • 2015-05-28
      相关资源
      最近更新 更多