JAVASCRIPT Tutorial
The location
object in JavaScript provides access to the current web page's URL and navigation-related methods.
location.href
to retrieve the full URL of the current page.location.href
to change the URL.location.hash
to set or retrieve the fragment identifier in the URL.location.reload()
to reload the current page.location.reload(true)
to reload without using the browser's cache.location.replace()
.window.location.assign()
for a delayed redirection.history.forward()
and history.back()
to navigate forward or backward in browsing history.document.title
to change the title of the current page.// Get current URL
const currentURL = location.href;
// Change URL to another page
location.href = "https://example.com";
// Reload page without cache
location.reload(true);
// Redirect to a new URL
location.replace("https://newsite.com");
This script demonstrates getting the current URL, changing the URL to a different page, reloading the page without cache, and redirecting to a new URL.