To redirect to another webpage using JavaScript, the code is as follows −
Example
<!DOCTYPE html>
<html>
<head>
<h1>Redirect to a Webpage Example</h1>
<button class="redirectBtn">Redirect</button>
<h2>Click the above button to Redirect to another Webpage</h2>
<script>
document .querySelector(".redirectBtn") .addEventListener("click", redirectFunction);
function redirectFunction() {
location.href("https://tutorialspoint.com/");
}
</script>
</body>
</html>Output
The above code will produce the following output −

On clicking the “Redirect” button we will be redirected to a new site −
