【JavaScript】window.location详解

简介

        在网页浏览器环境中,window.location是一个指向当前窗口的Location对象。它提供了一系列属性和方法,用于获取和操作当前页面的URL信息。


window.location属性

href

  • 描述:返回完整的URL。
  • console.log(window.location.href)

protocol

  • 描述:返回URL的协议部分,如 "http" 或 "https"。
  • console.log(window.location.protocol);

host

  • 描述:返回URL的主机名和端口号部分。
  • console.log(window.location.host);

hostname

  • 描述:返回URL的主机名部分。
  • console.log(window.location.hostname);

port

  • 描述:返回URL的端口号部分。
  • console.log(window.location.port);</

猜你喜欢

转载自blog.csdn.net/a451319296/article/details/132114062
今日推荐