How to parse query string by creating an anchor <a> element in JavaScript

1 Answer

0 votes
const url = "https://www.seek4info.com/search.php?type=sites&order=rand&query=wordpress+hosting";
 
const a = document.createElement('a');

a.href = url;

console.log(a.host);     
console.log(a.href);     
console.log(a.protocol); 
console.log(a.search);   

 
 
 
/*
run:
 
www.seek4info.com
https://www.seek4info.com/search.php?type=sites&order=rand&query=wordpress+hosting
https:
?type=sites&order=rand&query=wordpress+hosting
 
*/

 



answered May 23, 2021 by avibootz

Related questions

2 answers 279 views
1 answer 218 views
2 answers 368 views
368 views asked Feb 27, 2020 by avibootz
3 answers 538 views
...