SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to refresh the page automatically ?

    Hi ,

    I have a html page with displaying the rows available in the
    database table. It shows me all the rows when i come to that particular page.
    Suppose after some time some more records are added in the data base table and at this point my html should refresh the existing page and display all the rows available in the table..

    I should not click any button for refreshing or reloading the page
    but the java script code has to do it automatically after some time with out clicking any button.

    Please send me the code quickly

    Regards
    pavan

  2. #2
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,746
    Mentioned
    45 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    You don't even need Javascript for this.

    You can use this HTML meta tag in the head...


    <meta http-equiv="refresh" content="600">
    "Content" will be the length of your delay in seconds.




    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse

  3. #3
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,746
    Mentioned
    45 Post(s)
    Tagged
    0 Thread(s)
    And well, other than that you can set a timeout and go...

    window.location = window.location;
    ...so that when the timeout is up the page refreshes.




    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse

  4. #4
    SitePoint Guru
    Join Date
    Mar 2004
    Location
    Earth
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You shouldn't do this though - it's counter accessibility to refresh pages automatically, and in WCAG 2 this is a specific, named failure.

  5. #5
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks every one

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2007
    Posts
    1,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would not do it. People hate it when site refreshes when they do not do it themself.

  7. #7
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shaun(OfTheDead) View Post
    And well, other than that you can set a timeout and go...



    ...so that when the timeout is up the page refreshes.





    Thanks Shaun

  8. #8
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Rc,

    You hate it and i too hate it because it gets refreshed every time . But this is needed in certain palces so we gottu use it depending upon the requirement.

  9. #9
    SitePoint Addict agentforte's Avatar
    Join Date
    May 2007
    Location
    Toronto, ON, Canada
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the best method is with Ajax. This can get database information and display it without refreshing the page.

    The problem is I don't know how call a function every x seconds with javascript. I only know how to refresh the data with an onclick().

    Can anyone post a simple javascript that calls a function every x seconds?

  10. #10
    SitePoint Zealot
    Join Date
    Jul 2007
    Location
    London
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool

    If you insist on doing a refresh try iframes
    HTML Code:
                  <iframe src="url-to-external-htm-file.htm" name="tagboard" width="468px" height="60px" frameborder="0" marginwidth="0" marginheight="0"></iframe>
    Put the above in the page you want to display the info in. Adjust the height and width to suit yourself and adjust whatever else you need to adjust. CHange url-to-external-htm-file.htm to the path for the external file.
    Now create the external file and include this in the head
    HTML Code:
    <meta http-equiv="Refresh" content="30 >
    In the body of the new file add all the info that will need updating.

    An alternative is to use flash. This would get rid of any refreshing or try going ajax.

    Dunno if this will do you any good but...

  11. #11
    SitePoint Zealot
    Join Date
    Jul 2007
    Location
    London
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that post before mine came before i finished writing about the iframe

    musta been done while i was writing

  12. #12
    SitePoint Addict agentforte's Avatar
    Join Date
    May 2007
    Location
    Toronto, ON, Canada
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The iframe seems like a good choice, and allows people to use it without javascript. I still prever ajax.. it is easier to fit into your html and CSS, and interaction is more seemless, allowing you to send info to the database as well. (I'm not sure how the browser reacts when you click a submit button in an iframe)

  13. #13
    SitePoint Zealot
    Join Date
    Jul 2007
    Location
    London
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well depends on what the button does i suppose because the button and and all the other info that is to be updated will be in the external file that gets callled within the iframe so if you think its a good idea give it a shot and if the results ain't what you're expecting you drop the iframe idea and dedicate your time to going the ajax way

  14. #14
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can always do something like
    Code JavaScript:
    setInterval("ajaxReload()", 60000);
    instead of the onclick() event.

  15. #15
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    The easiest and most robust way to refresh the page is with the meta refresh command.
    http://en.wikipedia.org/wiki/Meta_refresh
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  16. #16
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah but the whole thread was people talking about how they didnt like when pages auto refreshed like that.


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
  •