Estoy enfrentando un problema en JS. window.location.href muestra la ubicación completa de una URL. window.location.hostname muestra el nombre de host. window.location.pathname muestra la ruta. pero qué code necesito usar para que se muestre la extensión.
Ejemplo
La URL es https://www.w3schools.com/js/tryit.asp?filename=tryjs_loc_href
yo obtengo
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_hrefSi no entiendes, mira la imagen.

mi codigo es
document.getElementById("demo").innerHTML = "The full URL of this page is:<br>" + window.location.href; <span id="demo"></span>Use la URL searchParams o simplemente location.search (aquí también disponible en la 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 filenamePD: recomiendo MDN sobre w3schools cualquier día