JavaScript Page Redirect

JavaScript can navigate the current page to another URL through location. For a normal navigation that should remain in Back history, use location.assign() or assign to location.href.

location.assign('https://www.example.com/');

The original tutorial used window.location = "..."; that form still navigates, but an explicit Location method often communicates intent more clearly.

window.location = 'https://www.example.com/';

The original self.location form is also retained as an equivalent reference inside a normal window:

self.location = 'https://www.example.com/';

If client-side JavaScript is disabled, a JavaScript-only redirect will not run. You can check the browser JavaScript-support example, but server-side HTTP redirects are usually the better choice when a redirect is required for routing, canonicalization, moved content, or SEO.

Redirect after a delay Top ↑

If a delayed transition is part of the interface, use a function callback with setTimeout(), not a string containing JavaScript. The original tutorial connected this topic to the JavaScript timer tutorial.

setTimeout(() => {
  location.assign('https://www.example.com/');
}, 10000);

The original example used a 10-second delay. If you deliberately delay a user-visible navigation, show the destination and remaining time, and provide a direct link so users are not trapped waiting.

Complete delayed redirect page

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>JavaScript page redirect</title>
</head>
<body>
  <p>You will be redirected after 10 seconds.
    <a href="https://www.example.com/">Open the destination now</a>.
  </p>
  <script>
  setTimeout(() => {
    location.assign('https://www.example.com/');
  }, 10000);
  </script>
</body>
</html>

Replace the current history entry Top ↑

Use location.replace() when the current page should not remain as a Back-history entry.

location.replace('https://www.example.com/');

Redirecting page based on Selection of Dropdown menu

Window Object Bookmark a page Displaying confirmation window




Subscribe to our YouTube Channel here



plus2net.com







sdaf

05-07-2010

Nice tutorial Great.



✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer