Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
Issue with anchor links on homepage

Im having issues with the anchor links on my homepage.

I have the following menu, which works great when the user is on the homepage but when visiting another page and clicking the "About" link it doesnt goto the homepage to find the anchor.

<nav class="main-menu">
        <a href="/#about">About</a>
        <a href="/contact">Contact</a>
</nav>

If I change the menu to the following, it works great when are on other pages, but when on the homepage (the url to my homepage is www.mysite.com/ (with nothing after the /)) and clicking "About" it loads the page again before going to the anchor point.

<nav class="main-menu">
        <a href="/home#about">About</a>
        <a href="/contact">Contact</a>
</nav>

Have been looking for a solution whereby:

  • When someone arrives at the homepage of my site (full url: www.mysite.com/) they can click "About" and will goto the anchor point (without refreshing the page).
  • When the user clicks "About" from a different page he will go back to the anchor point on the homepage (www.mysite.com/).

Many thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can fix this issue by simple javascript code. First write a function and then set condition that if you are in home page the url will be '#about' without home page the url will be '/#about'

Everything you can handle by DOM. Select the home page as variable by DOM then set condition

if(!home){const url = '/#about'}

and don't forget to call the function into menu link.

I think this method will work. Thanks

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda