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

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

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