How do I redirect my web page with JavaScript?

JavascriptWeb DevelopmentFront End Technology

You might have encountered a situation where you clicked a URL to reach a page X but internally you were directed to another page Y. It happens due to page redirection.

It is quite simple to do a page redirect using JavaScript on the client side. To redirect your site visitors to a new page, you just need to add a line in your head section as follows.


You can try to run the following code to learn how to use JavaScript to redirect an HTML page. Here, we will redirect to the homepage

 Live Demo

            function Redirect() {
      <p>Click the following button, you will be redirected to home page.</p>
      <input type = "button" value = "Redirect Me" onclick = "Redirect();" />
Published on 07-Feb-2018 16:14:24