QQ:285679784 欢迎加入博主CSDN资源QQ群799473954(附加信息:CSDN博客)一起学习 !
网站协议(http、https)
<script>
// document.location.protocol
// 返回:http: https: (注意含“:”字符)
alert(window.location.protocol);
alert(window.location.protocol.split(':')[0]); //不含“:”字符
</script>
网站域名+端口
<script>
// document.location.host
// 返回:www.domain.com:8080 (注意:80端口时,只显示域名)
alert(window.location.host);
</script>
网站域名
<script>
// 1、document.location.hostname
// 2、document.domain
// 返回:www.domain.com (1、2结果一样)
alert(document.domain);
alert(document.location.hostname);
</script>
网站协议+域名+端口
<script>
// window.location.protocol(网站协议:https、http)
// window.location.host (端口号+域名;注意:80端口,只显示域名)
// 返回:https://www.domain.com:8080
var path= window.location.protocol+'//' + window.location.host
alert(path);
</script>