SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2007
    0 Post(s)
    0 Thread(s)

    User configurable page refresh OR default setting

    I need to build a page that auto-refreshes on a default setting (5 seconds in my example) or allows the user to change the page reload time.

    I'm not quite sure how to do this, my line of thinking now is to set a cookie based on the value the user enters in the text field, then retrieve that value to set the form value when the page loads. I'm not sure if this is the best way, just what I'm thinking...

    The value the user enters needs to persist when the page reloads as well. For example, the page defaults to reloading every 5 seconds, but if the user changes it to 15, when the page reloads, 15 needs to be reflected in the text field, not the default 5. Plus, the setInterval value needs to be that same value.

    I've never done any cookie work before, is this the right way to go and can someone kind of steer me code-wise?

    Also, this is a one-off project for IE 6 only as well.

    This is what I'm starting with:

    <script type="text/javascript">
    //default time in milliseconds
    var howlong = 5000; 
    //user-config reload
    function setDelay() {
        var howlong = document.timer.reloadWindowValue.value * 1000; //convert to millis
        alert("setting to " + howlong + " milliseconds");
        setInterval(function() { location.reload() }, howlong);
    //default reload
    function reloadPage() {
        alert("reloading every " + howlong + " milliseconds");
        setInterval(function() { location.reload() }, howlong);
    window.attachEvent("onload", reloadPage)
    <form name="timer">
        Refresh page in: <input type="text" name="reloadWindowValue" size="3" value="5"> seconds
        <input type="button" value="set" onclick="setDelay();">

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Ventura, CA
    0 Post(s)
    0 Thread(s)
    A slightly easier method of doing this is the meta refresh tag. If you have some kind of server side scripting setup, you can just have a standard meta tag:

    <meta http-equiv="refresh" content="5">
    in the head to refresh every 5 seconds. Then you can have a form which posts to the same page and changes the value of content to the user selected value. You can either use a simple cookie, or simply store it in a session variable to grab later on if you want.


Posting Permissions

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