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

110
Visualizações
JS redirect function

I am trying to create a function that changes the redirect link of a button if the url contains the word "TicketPreDateable". So I have a button like this one:

<div class="col-12 col-md-6 col-xl-4" id="myproductid">
  <figure class="effect-product mx-auto"><img class="figure-img img-fluid" src="myimage">
    <figcaption><span class="badge badge-danger" style="top: -2.7em; background-color: red;">OFFRE SPÉCIALE</span>
      <h2 class="mt-0" style="color: white !important;"><span>My </span>Product Title</h2>
      <p>Profitez des pistes le samedi lorsque d'autres sont occupés à faire leurs valises ou coincés dans les bouchons. Un tarif unique à 24€ vous donne accès en toute liberté au domaine skiable pour la journée.</p>
      <a onclick="produrlmobile("https://www.mylink.com/fr/ProductsNgTicket/ticketPreDateable?poolNr=13&projNr=495&ticketTypeNr=122&preDatable=True&groupId=1&Day=11&Month=12&Year=2021")" href=""></a>
    </figcaption>
  </figure>
</div>

And my function look like this :

function produrlmobile(produrl) {
  if (produrl.includes("TicketPreDateable")) {
    if (window.innerWidth < 960) {
      window.location.href = produrl.replace(
        "TicketPreDateable",
        "TicketPreDateableMobile"
      );
    } else {
      window.location.href = produrl;
    }
  } else {
    window.location.href = produrl;
  }
}

I have the impression that it is because of special characters in the url that the function does not work, but I do not know how to avoid that.

Thank you for your help and have a nice day !

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

0

See Sarens comment for issues with the HTML.

Also, note that the replace method is case sensitive. In your function it looks like you are trying to replace the string TicketPreDateable, but the url only contains ticketPreDateable. I would recommend checking you are handling cases correctly, for both the old and new strings in the replace method arguments.

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