Home >Web Front-end >JS Tutorial >How Can I Redirect a User to a Different Webpage Using JavaScript?
Utilizing either jQuery or pure JavaScript, it's possible to seamlessly redirect users to another webpage.
Despite its popularity, jQuery is not recommended for performing redirects.
window.location.replace() mimics HTTP redirects effectively. It's preferred over window.location.href because it:
Redirect Method | Behavior |
---|---|
location.href | Simulates clicking on a link |
location.replace | Simulates an HTTP redirect |
To redirect using window.location.replace():
// Redirect to example.com window.location.replace("https://example.com");
The above is the detailed content of How Can I Redirect a User to a Different Webpage Using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!