Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda