PHP function for Javascript redirect

You may also like...

10 Responses

  1. toraj says:

    what is this code? please say more about that

    thanks a lot

  2. thinkdj says:

    Hi toraj,

    Sorry about that. It's a JavaScript echoed using PHP so that the destination URL and time before redirection could be called dynamically..

    Eg :

    js_redirect (http://google.com,5); //Redirects to Google after 5 seconds.

    js_redirect (http://google.co.in,15); //Redirects to Google.co.in after 15 seconds.

  3. toraj says:

    hello thinkdj

    so can i direct with this code myweblog to website ?

  4. thinkdj says:

    Toraj,

    I think the best for you would be a simpler META tag

    <code><meta http-equiv="refresh" content="0;URL =http://google.com"></code>

    Just add this in the within the <head> </head> of your html. Change 0 to an integer value for time to wait before redirecting..

  5. thinkdj says:

    You could also view the source of the following page for another JS redirect:

    http://www.tizag.com/javascriptT/examples/timedel

  6. Kirkorov says:

    Haha. It's funny.

  7. yeahboy says:

    this ain't working…

  8. yeahboy says:

    i guess you can make it as simple as this:

    function js_redirect($url, $seconds=1)

    {

    echo '';

    echo 'function redirect() {';

    echo 'window.location = "' . $url . '";';

    echo '}';

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

    echo '';

    return true;

    }

  9. yeahboy says:

    oh wtf.. nevermind. the code is being messed up by the blog.

  10. bosshakan says:

    great working thanks for sharing…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.