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

313
Visualizações
How to extract part of URL path and send URL onClick to query parameters

On my online art store I'm trying to achieve the following:

  • There's a "Contact me" button on the product page, I want the button to retrieve the artist's name from the URL and insert this into the button URL. URL structure of the product page: "https://store.com/product/smith-john-painting-1/".

Result at this point: clicking the "Contact me" button on this page leads the visitor to "https://store.com/contact/smith-john/"

  • Additionally, when the visitor visits the contact page through a product page and fills in the contact form, I want to know which product they viewed. A clean method of doing this (as I've understood from doing research) is by using query parameters. Therefore, using the example mentioned above: when the visitor views the product page and clicks the "Contact me" button, the part after the artist's name (however long that is), "painting-1", is extracted from the URL and added as query parameters as "?product=painting-1".

End result: clicking the "Contact me" button on the product page mentioned above leads the visitor to "https://store.com/contact/smith-john/?product=painting-1"

I've only found parts of the solution, any idea on how to achieve this?

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

0

Try this

const url = new URL("https://store.com/product/smith-john-painting-1/")
const artistUrl = url.origin

const parts = url.pathname.split("/")
const [lastName, firstName, item, number] = parts[2].split("-")
const pageUrl = `${artistUrl}/contact/${lastName}-${firstName}/?product=${item}-${number}`
console.log(pageUrl)

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