AnonymousJan 04, 2024
In this post, we will learn How to redirect to another webpage in Javascript.
// HTTP redirect
window.location.href = "http://www.techstackkit.com";
// HTTPS redirect
window.location.replace("http://www.techstackkit.com");
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Redirect Example</title>
</head>
<body>
<button id="redirectButton">Click me to redirect!</button>
<script>
const redirectButton = document.getElementById('redirectButton');
redirectButton.addEventListener('click', function () {
window.location.href = 'https:techstackkit.com';
});
</script>
</body>
</html>