How to parse URL in JavaScript

1 Answer

0 votes
const url = "https://www.seek4info.com/search.php?query=web+hosting";

const urlobj = new URL(url);

console.log(urlobj.hostname );
console.log(urlobj.href);
console.log(urlobj.origin);
console.log(urlobj.pathname);
console.log(urlobj.protocol);
console.log(urlobj.search);



/*
run:

www.seek4info.com
https://www.seek4info.com/search.php?query=web+hosting
https://www.seek4info.com
/search.php
https:
?query=web+hosting

*/

 



answered May 22, 2021 by avibootz

Related questions

2 answers 317 views
317 views asked Feb 1, 2025 by avibootz
1 answer 138 views
138 views asked Feb 1, 2025 by avibootz
1 answer 98 views
98 views asked Feb 1, 2025 by avibootz
1 answer 155 views
155 views asked Feb 1, 2025 by avibootz
1 answer 91 views
1 answer 95 views
1 answer 61 views
61 views asked Jan 31, 2025 by avibootz
...