How to redirect pages using Javascript?

Discussion in 'JavaScript' started by Hitul, Mar 28, 2007.

  1. #1
    Hi. How to redirect pages using javascript? Please tell me. Thanks in advance.
     
    Hitul, Mar 28, 2007 IP
  2. erotomania

    erotomania Banned

    Messages:
    291
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Here's my try


    <html
    <head>
    <title>Untitled Document</title>
    </head>

    <body onLoad="setTimeout(location.href='http://www.tvaddicts.tv', '3000')">
    <p>Redirecting to www.tvaddicts.tv Please Wait ....</p>

    </body>
    </html>



    3000 is a time in milliseconds
     
    erotomania, Mar 28, 2007 IP
  3. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #3
    using setTimeout and window.location, like so :

    
    <html>
    <head>
    <script language="javascript">
    function CountDown( )
    {
    	var current = document.getElementById('CountDown').innerHTML;
    	var next = current - 1;
    	document.getElementById('CountDown').innerHTML = next ;
    	if( next == 0 )
    	{
    		window.location.href = 'http://google.com';		
    	}
    	setTimeout( "CountDown()", 1000 );
    }
    </script>
    </head>
    <body onload="CountDown( );">
    Redirecting in <span id="CountDown">5</span>
    </body>
    <html>
    
    HTML:
     
    krakjoe, Mar 28, 2007 IP
  4. Hitul

    Hitul Peon

    Messages:
    76
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Actually i am making one login form. On submitting valid user name and password i should be redirected to welcome page otherwise it should goto page containing error message. I have put the validation using javascript for checking the fields whether they are blank or not. but i am not able to redirect the page. How to do it? I want to redirect the page to CGI script. Please help me. Thanks in advance.
     
    Hitul, Mar 28, 2007 IP
  5. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #5
    If it's a login form, then that form needs to be submitted for the user to be validated I would imagine, otherwise how do you check they have a valid username / password ?

    If you post the code you have currently things might be a little clearer for us.
     
    krakjoe, Mar 28, 2007 IP