---
title: "JavaScript Page Redirection"  
description: "JavaScript Page Redirection"  
author: "Danish Khan"  
published: 2012-10-22  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/1050/javascript-page-redirection  
category: "javascript"  
tags: ["javascript"]  
reading_time: 2 minutes  

---

# JavaScript Page Redirection

[Introduction](https://yourviews.mindstick.com/view/85450/mesopotamia-introduction-to-an-ancient-civilization):\

In this [article](https://yourviews.mindstick.com/view/81489/kashmir-now-after-an-year-of-abrogation-of-article-370) I am going to show how to [redirect](https://www.mindstick.com/forum/2005/radio-button-redirect) user to a page using Java Script, there is a function in Java Script which is used for the [redirection](https://www.mindstick.com/forum/436/url-redirection) purpose. Some time redirection is used to take users to a page depending on the their browser’s [version](https://www.mindstick.com/articles/12845/things-to-remember-while-migrating-odoo-to-a-better-version) and name.

Window.location : It is used to transfer the page to the specified url.

If the function is placed in the head section it is transferred as soon as the page is loaded, but when we call a function on a button it will be called when the [user clicks](https://answers.mindstick.com/qa/34556/if-a-user-clicks-all-the-google-ads-on-my-site-is-it-foul) on the button.

```
<html><head>    <script type="text/javascript"><!--
        function PageRedirect() {            window.location = "http://www.google.com";        }-->
    </script></head><body>    <p> If user clicks on the button page will be redirected</p>    <form>    <div>        <input type="button" value="Redirect Me" onclick="PageRedirect();" />    </div>    </form></body></html>
```

##### Output:

![JavaScript Page Redirection](https://www.mindstick.com/mindstickarticle/3a6934f8-96f2-486d-9e65-a1019c0f9a9c/images/91633dc6-295b-4597-b451-664fb396abe7.png)

As soon as the user clicks on button then he will be redirected to the google page.

If we want the page to be transferred as soon as the page loads we will write the

\

code at the head section and do not call at the button click like the example given

\

below:

```

<html>
<head>
    <script type="text/javascript">
        window.location = "http://www.google.com";
    </script>
</head>
<body>
    <p>
        As soon as the browsers loads it will be redirected to www.google.com</p>
</body>
</html>
```

\

##### Output of the above code:

![JavaScript Page Redirection](https://www.mindstick.com/mindstickarticle/3a6934f8-96f2-486d-9e65-a1019c0f9a9c/images/fbb0ce9a-8070-40a8-9a49-dd4f28469a80.png)

We can also use [setTimeout function](https://www.mindstick.com/forum/161268/how-does-the-settimeout-function-work) to transfer the page after some time (5 sec) has elapsed:

```
<html><head>    <script type="text/javascript">        function Redirect() {            window.location = "http://www.google.com";        }        document.write("You will be transferred to page after 5 sec.");        setTimeout('Redirect()', 5000);    </script></head><body></body></html>
```

##### Conclusion:

At last I conclude, from this article you can know the use of Java Script Page

\

Redirect method how to use it and how to transfer [one page](https://www.mindstick.com/forum/118/problem-in-display-content-of-one-page-to-another-page) from the other page

\

using window.location function.

\

---

Original Source: https://www.mindstick.com/articles/1050/javascript-page-redirection

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
