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

209
Visualizações
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 Respostas
Responde à pergunta

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 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