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

172
Views
How do I get the part of the url after the `?` in window.location

I am facing a problem in JS. window.location.href shows the full location of a URL. window.location.hostname shows the hostname. window.location.pathname shows the path. but what code do I need to use for the extension to show.
Example
URL is https://www.w3schools.com/js/tryit.asp?filename=tryjs_loc_href

I get

window.location.href: https://www.w3schools.com/js/tryit.asp?filename=tryjs_loc_href
window.location.hostname: www.w3schools.com
window.location.pathname: /js/tryit.asp
what code? = filename=tryjs_loc_href

if you don't understand Please see the picture

My Code is

document.getElementById("demo").innerHTML = "The full URL of this page is:<br>" + window.location.href;
<span id="demo"></span>

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

0

Use the URL searchParams or just location.search (here also available in the url

const url = new URL("https://www.w3schools.com/js/tryit.asp?filename=tryjs_loc_href")

const search = url.search; // or location.search

console.log(search.slice(1)); // remove the ?

console.log(url.searchParams.get("filename")); // or get just the filename

PS: I recommend MDN over w3schools any day

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!