类似的:
location对象的属性
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>location</title>
<script>
/*
url:统一资源定位符
完成的url:
中文版本 协议//主机名:端口号/路径?查询的字符窜#锚点
英文版本 protocol://hostname:port/pathname/?search#hash
① location.protocal:
1.file:本地磁盘文件访问
2.http:
3.https:(证书认证协议)
②location.hostname 主机名: IP(在全球范围内找到你当前网络的地址)
IP难记有4块,用域名就是IP的别称(像www.baidu.com)
③location.port 端口号(默认是隐藏的)
【注】是当前电脑中使用网络的软件,随机给他分配一个编号 0~65535
hostname:port 可以直接定位到当前使用网络的程序
小细节:浏览器 8080
http 80
https 443
④location.pathname 路径
⑤location.search 查询字符窜(前后端交互)
?name1=value1&name2=value2
⑥location.hash 锚点 #
*/
alert(location.protocol);//http:
alert(location.hostname);//127.0.0.1
alert(location.pathname);///javascript/63location%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%B1%9E%E6%80%A7.html
alert(location.search);//?name1=value1&name2=value2
alert(location.hash);//#1
alert(location);//object对象http://127.0.0.1:8848/javascript/63location%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%B1%9E%E6%80%A7.html
alert(location.href);//整个url string类型http://127.0.0.1:8848/javascript/63location%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%B1%9E%E6%80%A7.html
</script>
</head>
<body>
</body>
</html>