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

108
Visualizações
Preview URL for dynamically created link

I have a anchor tag. On click of it, I create an anchor tag and set the href attribute.

Something like this:

<a onClick={() => linkClick(url)}> Text </a>


 const linkClick = (url) => {
        const tag= document.createElement('a');
        tag.rel = 'noopener noreferrer';
        tag.target = _blank';
        tag.href = url;
        tag.click();
}

The issue I am facing here is, when I hover over the a tag, the URL preview is not available (Which usually appears at the bottom left) since href attribute is not present. Can you please help me here. (I dont want to add href attribute).

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

0

As far as I can tell, you have the dynamic URL when you render the link. Why not just render the component fully with React? If you are going to use React to render your component, I suggest you steer clear of changing the DOM element like that afterwards.

<a 
  href={url}
  rel="noopener noreferrer"
  target="_blank"
>
  Text
</a>
about 4 years ago · Juan Pablo Isaza Relatório

0

Add the href prop to the anchor tag, and then call preventDefault() in the linkClick` function like so:

<a href={url} onClick={linkClick}> Text </a>

 const linkClick = (e) => {
        e.preventDefault()
        const tag= document.createElement('a');
        tag.rel = 'noopener noreferrer';
        tag.target = '_blank';
        tag.href = e.target.href;
        tag.click();
}
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