Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Js Location in JavaScript

Js Location in JavaScript

? JavaScript Location Object

The location object contains information about the current URL and allows you to manipulate it. It’s part of the window object and is often used to get the current page address, redirect the browser, or reload the page.


? Common Properties of window.location

PropertyDescriptionExample Output
location.hrefFull URL of the current pagehttps://example.com/page.html
location.protocolProtocol used (http:, https:)https:
location.hostHostname and portexample.com:8080
location.hostnameHostname onlyexample.com
location.portPort number8080
location.pathnamePath after domain/page.html
location.searchQuery string (after ?)?id=123&ref=abc
location.hashAnchor part (after #)#section1

? Common Methods of window.location

MethodDescription
location.assign(url)Loads the specified URL
location.replace(url)Replaces current page with new URL (no history entry)
location.reload()Reloads the current page

? Example: Get Current URL

console.log(window.location.href);// Output: 'https://example.com/page.html'

? Example: Redirect to Another Page

window.location.href = "https://www.google.com";

or

window.location.assign("https://www.google.com");

? Example: Reload Page

window.location.reload();

Would you like an example to parse URL parameters or manipulate the URL dynamically?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql