四时宝库

程序员的知识宝库

window.location常用的对象属性(location对象相当于浏览器中的地址栏)

以网址 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

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言
    友情链接