Scheduled image substitution

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • google@ghosthounds.com

    Scheduled image substitution

    Hello...

    I have a website that hosts a java chat room nightly. I'd like to have
    a graphic on the main page that toggles between 2 images - one
    advertising the time of the chat, and another that appears during the
    time the chat is actually in session inviting visitors to the web site
    to join the chat.

    Any idea how I might do this in Javascript to schedule the imgage
    substitution using a general meridian time function?
    Thanks for your suggestions!

  • RobG

    #2
    Re: Scheduled image substitution

    google@ghosthou nds.com wrote:[color=blue]
    > Hello...
    >
    > I have a website that hosts a java chat room nightly. I'd like to have
    > a graphic on the main page that toggles between 2 images - one
    > advertising the time of the chat, and another that appears during the
    > time the chat is actually in session inviting visitors to the web site
    > to join the chat.
    >
    > Any idea how I might do this in Javascript to schedule the imgage
    > substitution using a general meridian time function?
    > Thanks for your suggestions!
    >[/color]

    Presumably the image changes based on the time at the server's
    location? Why not just have a script on your server that at a
    specified time replaces one image with the other?

    You have two source images: a.gif and b.gif. The image in the page is
    c.gif. At the specified time for chat to start, your server script
    copies a.gif to c.gif. At the next specified time, when chat ends,
    b.gif is copied to c.gif, and so /ad infinitum/.

    Maybe you need to "touch" the image to update the file creation time so
    cached images will update c.gif if you've changed it (but I don't think
    so).

    Look ma, no JavaScript!

    --
    Cheers, Rob.

    Comment

    • google@ghosthounds.com

      #3
      Re: Scheduled image substitution

      RobG wrote:[color=blue]
      > Why not just have a script on your server that at a
      > specified time replaces one image with the other?[/color]

      Because I'm even less familiar with server side scripting than I am
      with Javascript. ;)
      [color=blue]
      > You have two source images: a.gif and b.gif. The image in the page[/color]
      is[color=blue]
      > c.gif. At the specified time for chat to start, your server script
      > copies a.gif to c.gif. At the next specified time, when chat ends,
      > b.gif is copied to c.gif, and so /ad infinitum/.
      >
      > Maybe you need to "touch" the image to update the file creation[/color]
      time so[color=blue]
      > cached images will update c.gif if you've changed it (but I don't[/color]
      think[color=blue]
      > so).[/color]

      Hmmm... that seems extreme overkill for what I'm wanting to do. Maybe
      I wasn't clear in my original description, but all I want is a very
      basic javascript that, when the page is loaded, displays A.GIF for 22
      out of the 24 hours in a day. Except if the page is loaded, between
      say UTC 03 and UTC 05 - then it swaps the image with B.GIF

      Is a server side script really the better way to do that? I'm not
      really concerned that everyone has to see the "Chat now" image at
      exactly the same time - I.E. the time on the users PC is fine for the
      javascript to get the time from. Unless it can be called from the
      server itself in the javascript easily.

      Thanks for your input! :)

      Comment

      • Dr John Stockton

        #4
        Re: Scheduled image substitution

        JRS: In article <1102982812.250 323.184910@z14g 2000cwz.googleg roups.com>
        , dated Mon, 13 Dec 2004 16:06:52, seen in news:comp.lang. javascript,
        google@ghosthou nds.com posted :[color=blue]
        >
        >I have a website that hosts a java chat room nightly. I'd like to have
        >a graphic on the main page that toggles between 2 images - one
        >advertising the time of the chat, and another that appears during the
        >time the chat is actually in session inviting visitors to the web site
        >to join the chat.
        >
        >Any idea how I might do this in Javascript to schedule the imgage
        >substitution using a general meridian time function?
        >Thanks for your suggestions![/color]


        T = new Date().getUTCHo urs()
        src = ['a', 'b'][+(T>=20 && T<22)] + ".gif"

        will compute the name of the image to load, changing at 20h & 22h UTC.

        new Date()%864e5/36e5|0 // also gets UTC hour-of-day; note |

        If you want a Web page to change dynamically when the user's machine
        thinks the UTC is right,

        new Date()%864e5 // UTC millisecond-of-day

        can be used to compute the exact interval to the next status change, for
        a setTimeout to load the new image and recompute the interval.

        To be more exact, given the potential for user clock adjustment,
        calculate the image letter index once a minute and see if it has
        changed.

        If the times are not whole hours, divide by 6e4 instead to get minute of
        UTC day.

        BTW, not that it affects you, ISTM that a server cannot initially know
        the user's local time, but it may be able to get javascript to send it
        the user's offset from GMT.

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
        <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

        Comment

        • google@ghosthounds.com

          #5
          Re: Scheduled image substitution

          RobG wrote:[color=blue]
          > Why not just have a script on your server that at a
          > specified time replaces one image with the other?[/color]

          Because I'm even less familiar with server side scripting than I am
          with Javascript. ;)
          [color=blue]
          > You have two source images: a.gif and b.gif. The image in the page[/color]
          is[color=blue]
          > c.gif. At the specified time for chat to start, your server script
          > copies a.gif to c.gif. At the next specified time, when chat ends,
          > b.gif is copied to c.gif, and so /ad infinitum/.
          >
          > Maybe you need to "touch" the image to update the file creation[/color]
          time so[color=blue]
          > cached images will update c.gif if you've changed it (but I don't[/color]
          think[color=blue]
          > so).[/color]

          Hmmm... that seems extreme overkill for what I'm wanting to do. Maybe
          I wasn't clear in my original description, but all I want is a very
          basic javascript that, when the page is loaded, displays A.GIF for 22
          out of the 24 hours in a day. Except if the page is loaded, between
          say UTC 03 and UTC 05 - then it swaps the image with B.GIF

          Is a server side script really the better way to do that? I'm not
          really concerned that everyone has to see the "Chat now" image at
          exactly the same time - I.E. the time on the users PC is fine for the
          javascript to get the time from. Unless it can be called from the
          server itself in the javascript easily.

          Thanks for your input! :)

          Comment

          • Evertjan.

            #6
            Re: Scheduled image substitution

            wrote on 15 dec 2004 in comp.lang.javas cript:
            [color=blue]
            > Maybe
            > I wasn't clear in my original description, but all I want is a very
            > basic javascript that, when the page is loaded, displays A.GIF for 22
            > out of the 24 hours in a day. Except if the page is loaded, between
            > say UTC 03 and UTC 05 - then it swaps the image with B.GIF
            >[/color]

            <script type='text/javascript'>
            function lookfortime(){
            t= new Date()
            t= t.getUTCHours()
            if(t>2&&t<5)
            document.getEle mentById('a').s rc='b.gif'
            else
            document.getEle mentById('a').s rc='a.gif'

            setTimeout('loo kfortime()',600 00)
            }
            </script>

            <body onload='lookfor time()'>
            <img src='a.gif' id=a>

            NOT TESTED

            --
            Evertjan.
            The Netherlands.
            (Please change the x'es to dots in my emailaddress)

            Comment

            Working...