Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How does page redirection works in javascript?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 182
    Comment on it

    Sometimes you want to notify your visitors of the change of the new domain name when your webpage is moved. At that time it is good way to place a “redirect page” at the old location which, after a timed delay, will forward visitors to the new location of your webpage.

     You can do just this with a JavaScript redirection.

    1.Example code to redirect your visitors to a new site when they visit your site.

    <html>
    
    <head>
    
    <script type="text/javascript">
    
    function goto() {
    
    window.location="http://www.gamentio.com";
    
    }
    
    </script>
    
    </head>
    
    <body>
    
    <p>Goto new page.</p>
    
    <form>
    
    <input type="button" value="Goto Btn" onclick="goto();" />
    
    </form>
    
    </body>
    
    </html>

     By setting window.location equal to a new URL, you will in turn change the current webpage to the one that is specified. If you wanted to redirect all your visitors to www.gamentio.com when they arrived at your site,you need to write the above code.

    2.Example code if you want a delay before redirection to a new page.
     

    <html>
    
    <head>
    
    <script type="text/javascript">
    
    function delayGoto(){
    
        window.location = "http://www.gamentio.com"
    
    }
    
    </script>
    
    </head>
    
    <body onLoad="setTimeout(delayGoto ()', 10000)">
    
    <h2>Ready to be redirected!</h2>
    
    <p>Wait for few seconds!</p>
    
    </body>
    
    </html> 

    You will be redirected to gamentio.commain page in 10 seconds!

         We can also redirect to new pages based on some conditions like if you want your site visitors to go onto a different page based on their browsers.

 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: