JavaScript – How to Redirect to another Webpage

JavaScript

Deprecated: get_the_author_email is deprecated since version 2.8.0! Use get_the_author_meta('email') instead. in /home/cloudber/public_html/wp-includes/functions.php on line 4713

window.location.replace(...) is better than using window.location.href, because replace() does not keep the originating page in the session history, meaning the user will not have a chance in never-ending back-button fiasco.

In a nutshell:

To simulate someone clicking on a link, use window.location.href.

// similar behavior as clicking on a link
window.location.href = "https://www.cloudberry.com.my";

To simulate an HTTP redirect, use window.location.replace.

// similar behavior as an HTTP redirect
window.location.replace("https://www.cloudberry.com.my");

References:
MDN Web Docs – Window.location

Author: Wu Chia Chong

My main areas of interest are software architectures and software design methods, patterns, and new trends in software development.

Author: Wu Chia Chong

My main areas of interest are software architectures and software design methods, patterns, and new trends in software development.