Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!