Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to redirect a Web Page via Javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.96k
    Comment on it

    First question is that it is legitimate to use JavaScript redirect over other available options like Htaccess Redirect, html Redirect, Php redirect etc. as SEO point of view ?

    The answers is famous quote from Google Support itself.

    "Using JavaScript to redirect users can be a legitimate practice. For example, if you redirect users to an internal page once theyre logged in, you can use JavaScript to do so. When examining JavaScript or other redirect methods to ensure your site adheres to our guidelines, consider the intent. Keep in mind that 301 redirects are best when moving your site, but you could use a JavaScript redirect for this purpose if you dont have access to your websites server."

    WebPage redirect Javascript

    To redirect Just insert the below code in the head section of a web Page :

    <html>
       <head>
    
          <script type="text/javascript">
             <!--
                function Redirect() {
                   window.location="http://www.findnerd.com/";
                }
             //-->
          </script>
    
       </head>
    
       <body>
          <p>Click the Redirec button,to Redirect to http://www.findnerd.com .</p>
    
          <form>
             <input type="button" value="JavaScript Redirect" onclick="Redirect();" />
          </form>
    
       </body>
    </html>
    

    In above code the vital module is : window.location = "http://www.findnerd.com";

    Although, In JavaScript there are more complex ways to do it, according to your needs.

    window.location.href = 'Home.aspx';
    

    Above code will return the current URl, but by assigning your custom URL or Page Name, you can redirect to another page.

    window.location.replace('Home.aspx');
    

    Above code can be used as a method and we can pass our custom URL as it's parameter, and call this method, which will replace the current url and than you can not go back to previous page that you might have accessed.

    window.location.assign('Home.aspx');
    

    This can also be used as a method and we can pass our custom URL as it's parameter, and call this method, which will assign a new url and redirect to new page.

    In this blog we have discussed the various programming methods of doing web page / Website redirect. Hope it will help you in . If you have an query related to this Blog post or JavaScript, do post at FindNerd's JavaScript Forum.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: