MoreLesson 236Free preview
Redirect Webpage
This lesson is part of How To · All levels
Summary
This lesson discusses how to direct visitors to another page using JavaScript. Redirects are useful after logging in, after a form is sent, or when an old address has been moved. You'll compare window.location.href, assign(), and replace() and understand when redirects should be done on the server.
Key points
- Window.location.href = 'url' directs the browser to a new address and adds a history entry.
- Location.replace('url') change the current page without leaving the previous page on the Back button.
- Redirect can be delayed by settingTimeout, for example to display a successful message first.
- For permanent relocation and SEO, use HTTP 301 redirect on the server, not JavaScript.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.