In this article, you’ll learn how to redirect to a new page using javascript without a back button. We used the javascript’s window.location.replace()
method to redirect to a new page without a back button. We used the replace()
method because it removes the URL of the current document from the document history, which means it is not possible to use the "back" button to navigate back to the original document.
Here is the source code of the program to Redirect to a new page without the back button.
<!DOCTYPE html>
<html>
<head>
<title>Redirect to a New Page Without Back Button</title>
</head>
<body style="text-align: center;">
<h2>Welcome to <span style="color: purple;">Tutorials</span><strong>Rack</strong></h2>
<p>This is the example of <i>location.replace()</i></p>
<button onclick="redirect()">Click me</button>
<!--script to redirect from one webpage to another webpage without Back Button-->
<script>
function redirect() {
window.location.replace("https://www.tutorialsrack.com/");
}
</script>
</body>
</html>
I hope this article will help you to understand how to redirect to a new page using javascript without a back button.
Share your valuable feedback, please post your comment at the bottom of this article. Thank you!
Comments