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

206
Views
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 answers
Answer question

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