标签:meta 对象 locate htm location inf 页面 port path
1、location.href:返回当前页面的URL
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
document.write("当前页面的URL:");
document.write(location.href);
</script>
</body>
</html>

2、location.hostname:返回WEB主机的域名
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
document.write("WEB主机的域名:");
document.write(location.hostname);
</script>
</body>
</html>

3、location.pathname 返回当前页面的路径和文件名
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
document.write("当前页面的路径和文件名");
document.write(location.pathname);
</script>
</body>
</html>

有中文乱码现象。
4、location.port 返回 web 主机的端口
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
document.write("web 主机的端口 ");
document.write(location.port);
</script>
</body>
</html>

5、location.protocol 返回所使用的 web 协议
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
document.write("使用的 web 协议:");
document.write(location.protocol);
</script>
</body>
</html>

标签:meta 对象 locate htm location inf 页面 port path
原文地址:https://www.cnblogs.com/zhai1997/p/12222900.html