[JavaScript] window.location detailed explanation

Introduction

        In the context of a web browser, window.locationa Location object that points to the current window. It provides a series of properties and methods for obtaining and manipulating the URL information of the current page.


window. location Property

href

  • Description: Returns the full URL.
  • console.log(window.location.href)

protocol

  • Description: Returns the protocol part of the URL, such as "http" or "https".
  • console.log(window.location.protocol);

host

  • Description: Returns the hostname and port number portion of a URL.
  • console.log(window.location.host);

hostname

  • Description: Returns the hostname portion of a URL.
  • console.log(window.location.hostname);

port

  • Description: Returns the port number portion of the URL.
  • console.log(window.location.port);</

Guess you like

Origin blog.csdn.net/a451319296/article/details/132114062