SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Guru JoePrice's Avatar
    Join Date
    Jan 2002
    Location
    UK
    Posts
    673
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    redirecting to another page after 5 seconds

    Hi Chappies

    I have this page, that after 5 seconds I want to redirect to another page.
    Can anyone give me pointers as to how to go about doing this with javascript?

    i've got the window.location = 'myPAge.html' bit sussed

    its just the delay of 5 seconds that I cant figure out.
    I tried using <meta http-equiv> tag but there isnt a command for redirect? - only refresh?

    Any Ideas?

    Many thanks!

  2. #2
    SitePoint Zealot tcwatts's Avatar
    Join Date
    Jan 2003
    Location
    .my
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,

    refresh is the same thing:

    <META HTTP-EQUIV=Refresh CONTENT="10; URL=myPAge.html">

    10 being the number of seconds

  3. #3
    SitePoint Guru JoePrice's Avatar
    Join Date
    Jan 2002
    Location
    UK
    Posts
    673
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the response.


    i tried that however,
    it just refreshes the current page and does not redirect to the page specified in the URL bit

  4. #4
    SitePoint Enthusiast trifolic's Avatar
    Join Date
    Sep 2003
    Location
    NY
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using this in your index.php file

    Code:
    <?php
    header('Refresh: 5; URL=http://www.redirecturl.extension');
    ?>
    Do you have news? Want it published?
    Visit http://www.w3reports.com -Daily News for Webmasters
    Get FREE News for your site by clicking here

  5. #5
    SitePoint Guru JoePrice's Avatar
    Join Date
    Jan 2002
    Location
    UK
    Posts
    673
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks trif, will give it a go

  6. #6
    SitePoint Guru JoePrice's Avatar
    Join Date
    Jan 2002
    Location
    UK
    Posts
    673
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sadly I got an error:

    Warning: Cannot add header information - headers already sent

    Any other ideas? Using either javascript or php?

    Thanks

  7. #7
    SitePoint Enthusiast trifolic's Avatar
    Join Date
    Sep 2003
    Location
    NY
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What page are you trying to do this with? Please post the URL so I can check it out and come up with a solution for you.
    Do you have news? Want it published?
    Visit http://www.w3reports.com -Daily News for Webmasters
    Get FREE News for your site by clicking here

  8. #8
    SitePoint Guru JoePrice's Avatar
    Join Date
    Jan 2002
    Location
    UK
    Posts
    673
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its currently running offline on my apache server on my pc.
    don't really want to put it live at the moment

    Chances are i'm already sending header information to that page which has the error

    there must be an easy way to delay a window.location command by 5 seconds!

  9. #9
    SitePoint Enthusiast trifolic's Avatar
    Join Date
    Sep 2003
    Location
    NY
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Javascript will do it, But there is still alot of people that have it disabled, thus they would be stuck at that page for a while. The best way would be to use one of the above solutions. If you could post the code of the page you are trying to do this on, I might be able to help find a way around the headers problem
    Do you have news? Want it published?
    Visit http://www.w3reports.com -Daily News for Webmasters
    Get FREE News for your site by clicking here

  10. #10
    SitePoint Wizard silver trophybronze trophy asp_funda's Avatar
    Join Date
    Jun 2003
    Location
    ether
    Posts
    4,482
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    the meta tag is:

    Code:
    <meta http-equiv="Refresh" content="5;url=myPAge.html">

    the JavaScript Code is:

    Code:
    function redirectME()
    {
    window.location.href = "myPAge.html";
    clearTimeout();
    }
    setTimeout("redirectME()", 5000);

    Use any of the above, both are same.



    As for the headers problem in PHP, put that command before any html tag. Best place to put it is at the very beginning of the file.
    Our lives teach us who we are.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Me - Photo Blog - Personal Blog - Dev Blog
    iG:Syntax Hiliter -- Colourize your code in WordPress!!

  11. #11
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    .......
    <head>
    <script type="text/javascript">
    
    onload = function()
    {
        setTimeout('self.location="myPAge.html"', 5000);
    }
    
    </script>
    </head>
    ......
    This does nothing (no timer ID supplied), and is unnecesary: clearTimeout();

    http://tech.irt.org/articles/js021/
    ::: certified wild guess :::


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •