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

207
Vistas
How do I change URL values in JavaScript

I have create small webpage, I need change original URL for example now I redirected http://localhost/single-pages/?id=10 working fine, But I want to change URL structure of http://localhost/single-pages/10. How do I hide or mask query string value of "?id=". Could you please help me any one.

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

0

You could replace the ?id=10 by

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

Now you can append the parameter of the search like

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

And you have different possibilities to set the URL, one is (without reloading)

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