专业编程基础技术教程

网站首页 > 基础教程 正文

window.location常用的对象属性(location 对象)

ccvgpt 2024-07-24 11:10:52 基础教程 8 ℃
以网址 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

最近发表
标签列表