How to get the current domain name in JavaScript

2 Answers

0 votes
const domainName =  document.domain;

console.log(domainName); 

  
    
    
/*
run:
    
"www.seek4info.com"
    
*/

 



answered Jan 11, 2019 by avibootz
edited Feb 23, 2021 by avibootz
0 votes
const domainName =  window.location.hostname;

console.log(domainName); 

  
    
    
/*
run:
    
"www.seek4info.com"
    
*/

 



answered Feb 23, 2021 by avibootz

Related questions

1 answer 171 views
1 answer 199 views
...