完整的URL地址:https://editor.csdn.net/md?articleId=108160875
http :–>使用的协议,protocol
editor.csdn.net -->域名,hostname
md–>pathname
?articleId=108160875–>url的参数search
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>location对象</title>
<script>
//就是完整的url地址
var f=function () {
//location的组成部分
document.write(location.href);//整个地址
document.write("<br>");
document.write(location.protocol);//协议
document.write("<br>");
document.write(location.host);//主机+端口号
document.write("<br>");
document.write(location.hostname);//端口号
document.write("<br>");
document.write(location.pathname);//资源
document.write("<br>");
document.write(location.search);//参数
}
//打开一个新的页面
var f2=function () {
}
</script>
</head>
<body>
<input type="button" value="ceshi" onclick="f() ">
</body>
</html>