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

151
Views
Agregar parámetros de URL actuales al enlace de anclaje

En una página como

https://www.example.com/?firstname=Steven&lastname=Smith&email=steve%40gmail.com&phone=0404555555

Tengo un botón (enlace de anclaje) #ptsBlock_553944 .ptsCell:nth-of-type(1) .ptsEditArea.ptsInputShell que enlaza con https://www.example.com/form

Me gustaría agregar los parámetros de URL de la URL actual a la URL del botón, de modo que el href del botón ahora sea https://www.example.com/form/?firstname=Steven&lastname=Doig&email=steve%40gmail.com&phone=0404555555

¿Cómo puedo hacer esto con JavaScript, por favor?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Utilice window.location.search :

 var url = "https://exmaple.com"; var newurl = url + window.location.search;

newurl contendrá todos los datos get (por ejemplo, ?something=something&something2=something5 ).

Para cambiar el href de a :

 var button = document.getElementById('#ptsBlock_553944'); button.href = button.href + window.location.search;
about 4 years ago · Juan Pablo Isaza Report

0

Si no le importa admitir navegadores más antiguos, puede usar la API de URL y URLSearchParams .

 function appendCurrentUrlSearchParams(anchorElement) { const currUrlSearchParams = new URL(window.location.href).searchParams; const link = new URL(anchorElement.href); // uncomment this line if you want to clear query parameters already present in the anchor url // link.search = ''; for (const entry of currUrlSearchParams.entries()) { link.searchParams.append(entry[ 0 ], entry[ 1 ]); } anchorElement.href = link.href; }

Uso en su caso:

 appendCurrentUrlSearchParams(document.querySelector('#ptsBlock_553944 .ptsCell:nth-of-type(1) .ptsEditArea.ptsInputShell'));
about 4 years ago · Juan Pablo Isaza Report

0

Lea Html select usando select para cambiar el enlace de un botón con Javascript

específicamente la sección de

  1. Obtenga el elemento con algo como document.getElement MDN getElement Link

  2. Cambia el .href de ese elemento a lo que quieras.

 function selectFunction() { var x = document.getElementById("selectopt").value; document.getElementById("mylink").innerHTML = x; document.getElementById("mylink").href = "http://www." + x + ".com"; }
 document.location.pathname = '/questions/69240453/appending- current-url-parameters-onto-anchor-link/69240510'; //get the document pathname I chose from document.location let data = document.location.pathname; let preUrlString = 'www.example.com/form'; let newString = preUrlString + data; console.log(newString); 'www.example.com/form/questions/69240453/appending- current-url-parameters-onto-anchor-link/69240510' document.getElementById("mylink").href = newString;
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!