The window.location object is used to get the current page URL and it redirects the browser completely to a new page. It can be written without the prefix i.e., window-like location.href, and location etc., Some of the types of window location as follow −
location = URL or location.href = URL
URL − Used to specify the URL
Step 1 − Under the body section, we defined the heading, button and script elements.
Step 2 − Let’s define the style for the heading element of the HTML Document.
Step 3 − For the button element, the myLocation() method is defined. Using this method location will be changed when we press the button.
Step 4 − In myLocation() method, the location URL is mentioned clearly for which method functionality should be performed.
Step 5 − After clicking the button, the onClick event function is triggers and it changes the URL location.
In this article, we have demonstrated how to set the location and location.href along with examples. We have seen the two different examples here, we used the location property for setting the location of the URL. In the first and second example, we used the ‘location and location.href’ properties for setting the designated URLs.
- Related Articles
- How to use the Set-Location command in PowerShell?
- How to copy items from one location to another location using PowerShell?
- How to use Location API in Android to track your current location using Kotlin?
- How to set location of JLabel in a JFrame with Java?
- How to set the location of a button anywhere in JFrame?
- How to use Push-Location and Pop-Location command in PowerShell?
- How to select a directory and store the location using Tkinter in Python?
- How to download any file and save it to the desired location using Selenium Webdriver?
- How can I set the location of minor ticks in Matplotlib?