This article describes how to obtain domain names by js. Share it for your reference. The specific implementation method is as follows:
Copy the code as follows:<script>
//Get the domain name
var k_host = window.location.host;
var k_host2 = document.domain;
//Get the full address of the page
var k_url = window.location.href;
</script>
The operation results are as follows:
k_host:www.VeVB.COM
k_host2:www.VeVB.COM
k_url://www.VeVB.COM/article/60420.htm
Replenish:
location.hostname Returns the domain name of the web host
location.pathname Returns the path and file name of the current page
location.port Returns the port of the web host (80 or 443)
location.protocol Returns the web protocol used (http:// or https://)
I hope this article will be helpful to everyone's JavaScript programming.