JavaScript Window Location
Introduction
The window.location
object in JavaScript is a powerful tool that provides information about the current URL of the web page and allows you to manipulate it. This object is a property of the window
object, which represents the browser's window. In this article, we will explore the various properties and methods of the window.location
object and how they can be used to enhance the functionality of web applications.
Properties of window.location
The window.location
object has several properties that provide different parts of the URL:
href
: This property returns the entire URL of the current page.protocol
: This property returns the protocol used in the URL, such ashttp:
orhttps:
.host
: This property returns the hostname and port number of the URL.