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

141
Views
How to change the hash (#) in the query string URL to another identifier with javascript?

I'm having trouble trying to find an item that has a hash (#), I want to change the hash in the url to another identifier. For example, I have a url like this => http://localhost:8088/stores/1/brands?q=# When searching with a hash, the url will change to something like this => http://localhost:8088/stores/1/brands?q=%23

How to replace like that and push it to current url?

let currentUrl = 'http://localhost:8088/stores/1/brands?q=#';
let url = new URL(currentUrl);

url.searchParams.set("q", "#"); // setting param
url.hash='';

let newUrl = url.href; 
console.log(newUrl);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

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

0

you can use replace

let currentUrl = "http://localhost:8088/stores/1/brands?q=#";
str = currentUrl.replace("#", "023");
console.log(str);

Update :

if you want to set the url you can use

location.href = str;

but in order to stop the infinite loop you need to add a extra para like

    let currentUrl = "http://localhost:8088/stores/1/brands?q=#";
    str = currentUrl.replace("#", "023");
    console.log(str);
var hash = url.searchParams.get("hashset");
    if(hash !== "1") {
console.log(str+"&hashset=1");
location.href = str+"&hashset=1";
} else {
console.log("hash already set")
}
about 4 years ago · Juan Pablo Isaza Report

0

You can use the function encodeURIComponent.

E.g.

encodeURIComponent("#") // gives %23

You can read the detail on MDN docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

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!