领先的免费Web技术教程,涵盖HTML到ASP.NET

网站首页 > 知识剖析 正文

window.location常用的对象属性

nixiaole 2024-11-24 19:56:28 知识剖析 15 ℃
以网址 https://mp.toutiao.com:8888/search?q=123#hash 为例子说明对应的属性值

location.origin				//协议+域名+端口
返回: https://mp.toutiao.com:8888

location.hostname //web主机的域名
返回:mp.toutiao.com

location.host  //主机的域名+端口
返回:mp.toutiao.com:8888

location.pathname //当前页面的路径和文件名
返回:/search/

location.port          //web的端口
返回:8888

location.protocol   //web协议http:// 或 https://
返回:https:

location.href 					//当前页面的 URL
返回:https://mp.toutiao.com:8888/search?q=123#hash

location.search       //?以及后面参数部分(包含?)
返回:?q=123

location.hash         //锚点
返回:#hash
最近发表
标签列表