How to Redirect to Another Page in JavaScript

When you move your website to another domain or relocate pages on the same domain, you should redirect your old pages to the new ones. This helps visitors find the new location of your content. The best way to redirect websites and pages is to configure the server to perform the redirect automatically so that search engines will follow the redirect. However, if you don't have access to the server, you can use JavaScript Page (JSP) to redirect visitors.

Instructions

    • 1

      Open the file for the page you want to redirect. You can open the file in an editor provided by your host or in an offline editor such as Notepad.

    • 2

      Type the following at the top of the page:

      <script language="javascript" type="text/javascript">
      <!--
      window.location="New Page URL";
      // -->
      </script>

      Replace "New Page URL" with the full address to the new page, including "http."

    • 3

      Save and close the file. If you are using an online editor, the changes take effect immediately. If you are using an offline editor, upload the page to your site for the changes to take effect.

Tips & Warnings

  • Google does not follow JavaScript redirects as they are commonly used to fool search engines. Only use JavaScript redirects if you don't have access to the server to set up redirects.

Related Searches:

References

Comments

Related Ads

Featured