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

213
Views
¿Cómo cambio los valores de URL en JavaScript?

He creado una pequeña página web, necesito cambiar la URL original, por ejemplo, ahora redirigir http://localhost/single-pages/?id=10 funciona bien, pero quiero cambiar la estructura de URL de http://localhost/single-pages /10. ¿Cómo escondo o enmascaro el valor de la cadena de consulta de "?id=". ¿Podría por favor ayudarme a alguien?

 <html> <head> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> </script> </head> <body> <div class="sampleLink">Link here</div> </div> <script type="text/javascript"> $(document).ready(function(){ var link="http://localhost/single-pages/?id=10"; $('.sampleLink').append("<a href="+link+">New Link Here</a>"); console.log(window.location); }); </script> </body> </html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Podrías reemplazar el ?id=10 por

 const locationSearch = window.location.search; const locationWithoutSearch = window.location.replace(locationSearch, '');

Ahora puede agregar el parámetro de la búsqueda como

 const params = new URLSearchParams(locationSearch); const pageId = params.get('id');

Y tienes diferentes posibilidades para configurar la URL, una es (sin recargar)

 window.history.pushState({}, '', `/single-pages/${pageId}`);
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!