Simple Page Redirect
The foundation of JS navigation. Learn the standard method for programmatically moving a user from one page to another.
Click below to trigger a redirect simulation:
Copy the Script
<script>
function redirectUser() {
// Standard Redirect (Keeps History)
window.location.href = "http://www.google.com";
// OR Replace History (No Back Button)
// window.location.replace("http://www.google.com");
}
</script>
<button onclick="redirectUser()">Click to Move</button>
Frequently Asked Questions
`window.location.href = url` acts like a standard click (user can click Back). `window.location.replace(url)` replaces the current history entry, so the Back button won't work (good for login redirects).
For permanent moves (301), server-side redirects (.htaccess or PHP) are much better for SEO. JavaScript redirects are okay for logic-based routing (e.g., login success).
Yes, you can append query strings to the URL: `window.location = 'page.php?user=123'`.