Tiny Frontend Logo
Posts 0115

On This Page

JavaScript: Page Location

Whether you're a seasoned developer or just starting your journey, understanding how to manipulate the web page's location through JavaScript can be a very useful tool in your arsenal.

From redirecting users to different pages to extracting valuable information about the current URL, location offers a wealth of functionality that every developer should master.

The Location Object

The location object can be accessed using the following ways:

  • location
  • window.location
  • document.location

Here's a breakdown of the multiple properties that it's comprised of. To understand better, let's take the following example URL:

https://tinyfrontend.com/like/comment?q=follow&page=1#subscribe

Location.href

The whole URL is contained in this property as a string. You can assign a new value to this property to replace the current page with the new one.

// Another webpage on the same website
location.href = "/some/other/path"

// Another website
location.href = 'https://google.com'

// Also Works!!
location = 'https://google.com'
Subscribe to read the full content

* Free subscribe to enjoy full content access.
* You can cancel anytime with 1-click.

Read Next

0114

Cookies

As a frontend developer, understanding how cookies work is essential for building robust web applications. In this article, we'll explore the world of browser cookies, demystify their mechanics, and learn how to harness their power in your projects.

0113

JavaScript: Local Storage

Understanding how to store data on the client side is essential for creating robust web applications. In this article, we'll explore local storage, one of the key mechanisms for caching data within the user's browser. Let's dive in!

0112

JavaScript: Session Storage

As a frontend developer, understanding how to store data on the client side is crucial. In this article, we’ll delve into the world of web storage, specifically focusing on session storage. Let’s explore what it is, how it works, and when to use it.

JavaScript: Session Storage
0110

Cross-Origin Resource Sharing (CORS)

Please imagine you're building a spiffy weather application using JavaScript and you want to display live weather data from a popular weather service.

Cross-Origin Resource Sharing (CORS)
0109

Cross-Site Scripting (XSS) in JavaScript

Cross-Site Scripting (XSS) is a web security vulnerability that allows an attacker to inject malicious code into a web page that is viewed by other users.

Cross-Site Scripting (XSS) in JavaScript
0108

Multiple Promises Handling in JavaScript

Promises are a powerful way to handle asynchronous operations in JavaScript. They allow us to write clean and readable code, without using callbacks or nested functions.

Multiple Promises Handling in JavaScript