ASPit - Totally ASP JSit - Totally JavaScript

PHPit - Totally PHP

Search PHPit

Use this textbox to search for articles on PHPit. Seperate keywords with a space.

Advertisements

Javascript Redirect

With this function you can easily redirect to another page, after a certain amount of time (in seconds).

<?php
function js_redirect($url$seconds=5) {
    echo 
"<script language=\"JavaScript\">\n";
    echo 
"<!-- hide from old browser\n\n";
    
    echo 
"function redirect() {\n";
    echo 
"window.location = \"" $url "\";\n";
    echo 
"}\n\n";

    echo 
"timer = setTimeout('redirect()', '" . ($seconds*1000) . "');\n\n";

    echo 
"-->\n";
    echo 
"</script>\n";

    return 
true;
}
?>

4 Responses to “Javascript Redirect”

  1. sivakumar Says:

    Thank you very much

  2. gpm1982 Says:

    Why not do it using just plain PHP? It will be much easier to just create something like below:

  3. a2z Says:

    because if you did it in plain php header, you wouldnt be able to edit cookies and have them affect the current page.

  4. hero Says:

    where do i put the page i want it to redirect too??

Leave a Reply