How to Redirect to Another WebPage Using JavaScript

In this short tip post, we will learn how to perform redirection to another webpage using JavaScript.


We need to redirect the user to another webpage on a particular event, say when user clicks on a button.


We can use window.location.href function of JavaScript to achieve the same.


Here is the code.

<title>Hello World</title>
<script type='text/javascript'>
function redirect() {
    <input type='button' value='clickme' onClick='redirect()'>

Check out the codepen for the live demo.

See the Pen
by Shahid Shaikh (@codeforgeek)
on CodePen.

Love JavaScript? Learn more about it here.


Founder of Codeforgeek. Technologist. Published Author. Engineer. Content Creator. Teaching Everything I learn!

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.