Javascript Page Redirect

tutorial and example
tutorial and example

JavaScript Page Redirect

The window.location object can be used to get the current page address (URL) and to redirect browser to new page.

In some websites when we visit, we face a situation where we clicked a URL to reach a page X but internally it directed us to another page Y. It happens due to Page redirection.

How Page Redirect Works.

The implementation of Page redirect are as follows:

Example 1

When we use JavaScript at client side it is quite simple to use of Page Redirect. Need to add a line in head section to redirect the site visitors to a new page.

Try Now

Example 2

To show a convenient message to visitors before redirecting them to new page. We use setTimeout() is built-in JavaScript function which is used to execute function after a given interval of time.

Try Now

Example 3

In this example shows how to redirect the visitors onto a different page based on their browsers.

Try Now