Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda