English 中文(简体)
Javascript - Page Redirect
  • 时间:2024-11-03

JavaScript - Page Redirection


Previous Page Next Page  

What is Page Redirection ?

You might have encountered a situation where you cpcked a URL to reach a page X but internally you were directed to another page Y. It happens due to page redirection. This concept is different from JavaScript Page Refresh.

There could be various reasons why you would pke to redirect a user from the original page. We are psting down a few of the reasons −

    You did not pke the name of your domain and you are moving to a new one. In such a scenario, you may want to direct all your visitors to the new site. Here you can maintain your old domain but put a single page with a page redirection such that all your old domain visitors can come to your new domain.

    You have built-up various pages based on browser versions or their names or may be based on different countries, then instead of using your server-side page redirection, you can use cpent-side page redirection to land your users on the appropriate page.

    The Search Engines may have already indexed your pages. But while moving to another domain, you would not pke to lose your visitors coming through search engines. So you can use cpent-side page redirection. But keep in mind this should not be done to fool the search engine, it could lead your site to get banned.

How Page Re-direction Works ?

The implementations of Page-Redirection are as follows.

Example 1

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

<html>
   <head>
      <script type = "text/javascript">
         <!--
            function Redirect() {
               window.location = "https://www.tutorialspoint.com";
            }
         //-->
      </script>
   </head>
   
   <body>
      <p>Cpck the following button, you will be redirected to home page.</p>
      
      <form>
         <input type = "button" value = "Redirect Me" oncpck = "Redirect();" />
      </form>
      
   </body>
</html>

Output