Given a URL, the task is to use the current address of the page and to perform an operation using this address.
Example 1: This example points to the same URL and only redirects to the same address.URL = ‘https://gitstr.herokuapp.com’
Before clicking on the Search button: Search
After clicking on the Search button:
as you can see after clicking the search button the URL doesn’t change because of line 38: window.location.href = ‘/’.
Example 2: In this example we would like to use window.location.href property
to point to some other address, so let’s see how it works.
Before clicking on the button: Search
After clicking on the button: Search
as you can see after clicking the search button the URL does changes because
of line 37: window.location.href = ‘/’ + input, now it refer to the default window location + input.
so this was a brief example showing how I use window.location.href property in my projects, if you want to get a better understanding of the topic and how it actually works when complete backend and frontend is involved then do refer to this Github repo.
- How to Set Calc Viewport Units Workaround in CSS ?
- Workaround to backdrop-filter in CSS
- How to make a redirect in PHP?
- How to make a placeholder for a 'select' box?
- How to make the cursor to hand when a user hovers over a list item using CSS?
- How to make sure that Apache service keeps running in Ubuntu
- How to make div not larger than its contents using CSS?
- Step by step guide to make your first Wordpress Plugin
- How to make div height expand with its content using CSS ?
- How to make an image center-aligned (vertically & horizontally) inside a bigger div using CSS?
- How to make a vertical line using HTML ?
- How to make flexbox children 100% height of their parent using CSS?
- How to make text input non-editable using CSS?
- How to make a div fill a remaining horizontal space using CSS?
- How to make elements float to center?
- Best way to make a d3.js visualization layout responsive
- How to make horizontal line with words in the middle using CSS?
- How to make horizontal scrollable in a bootstrap row?
- How to make dynamic chart in PHP using canvasJS?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.