JavaScript Custom EventHandlers?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gueorguiev Stefan Gueorguiev

    #1

    JavaScript Custom EventHandlers?

    Hi,

    I have the following problem that I can't seem to find a solution to.

    I have a jsp webserver and it creates webpages containing different things
    and amongst them there is field with an image that should be changing
    (like a slideshow). The problem is that I don't know beforehand the timing
    of the changes. The image should change when an event occurs (e.g. a
    person presses a key), but that event has to occur on the server (or on
    another computer but definetely not on the client).
    Now one solution is when the event occurs on the server to just generate
    the html all over and send it again but I don't want to do that. I want
    the image to change but I don't want the whole webpage to reload.

    So I was wondering can a custom event handler be implemented in javascript
    such that when some event happens elsewhere, not on the client, my
    handler will catch it and perform the required operation?

    Thanks in advance,
    Stefan
  • kaeli

    #2
    Re: JavaScript Custom EventHandlers?

    In article <Pine.LNX.4.58. 0505131227400.1 0662@seawolf.cd f>,
    c4gueorg@cdf.to ronto.edu enlightened us with...[color=blue]
    >
    > So I was wondering can a custom event handler be implemented in javascript[/color]

    Javascript runs on the client. And only the client.
    (excepting jscript.net)
    [color=blue]
    > such that when some event happens elsewhere, not on the client, my
    > handler will catch it and perform the required operation?[/color]

    So, that would be a 'no'.
    You can't trap events that are occuring somewhere other than the client from
    the client.

    You're dealing with a client-server situation here. Stateless. Once the
    server is done processing and sends to the client, that's it.
    You could implement some sort of timer on the client that polls the server
    for changes and updates the image as appropriate, but you do have to initiate
    the polling from the client to the server. You can't push from the server to
    the client without some sort of request. After all, once it's done, the
    packets are sent, the server has no idea which client to push TO.

    This is assuming standard client-server web app architecture, since you
    mentioned JSP and webserver and all.

    --
    --
    ~kaeli~
    Found God? If nobody claims Him in 30 days, He's yours to
    keep.



    Comment

    • Gueorguiev Stefan Gueorguiev

      #3
      Re: JavaScript Custom EventHandlers?

      Ok I got it but there is one more thing then I have a follow-up question.
      [color=blue]
      > You could implement some sort of timer on the client that polls the server
      > for changes and updates the image as appropriate, but you do have to initiate
      > the polling from the client to the server.[/color]

      Yeah I guess I'll have to do this, the question is how? I know how to do
      the timing but how would I contact the server? So far I am familiar with
      javascript functions that access only the current document. Are there any
      that access an arbitrary server (e.g. MySQL) and pull out info from it? If
      so, could you direct me to where I can find out more about this set of
      function. I tried looking up on google but without much success.

      Thanks,
      Stefan

      Comment

      • kaeli

        #4
        Re: JavaScript Custom EventHandlers?

        In article <Pine.LNX.4.58. 0505131355040.1 1674@seawolf.cd f>,
        c4gueorg@cdf.to ronto.edu enlightened us with...[color=blue]
        > I know how to do
        > the timing but how would I contact the server?[/color]

        Various ways.
        The newest is using xmlhttprequest. Search the archives here, as it's been a
        common discussion lately.
        If it isn't an option for you for whatever reason, you can make dynamic
        script elements and have that source call a script on the server that returns
        javascript.
        I did that approach for some dynamic content and put up a little thing about
        it here.


        [color=blue]
        > javascript functions that access only the current document. Are there any
        > that access an arbitrary server (e.g. MySQL)[/color]

        No. Not exactly.
        It has to call server-side script that does things.
        Basically it's like a web service, kinda sorta. It just makes a request to a
        web server. What the request does is up to you.

        --
        --
        ~kaeli~
        Time flies like an arrow. Fruit flies like a banana.



        Comment

        • Gueorguiev Stefan Gueorguiev

          #5
          Re: JavaScript Custom EventHandlers?

          Seems like xmlhttprequest is exactly what I needed! I just didn't
          know it existed:)

          Thanks a lot!

          On Fri, 13 May 2005, kaeli wrote:
          [color=blue]
          > In article <Pine.LNX.4.58. 0505131355040.1 1674@seawolf.cd f>,
          > c4gueorg@cdf.to ronto.edu enlightened us with...[color=green]
          > > I know how to do
          > > the timing but how would I contact the server?[/color]
          >
          > Various ways.
          > The newest is using xmlhttprequest. Search the archives here, as it's been a
          > common discussion lately.
          > If it isn't an option for you for whatever reason, you can make dynamic
          > script elements and have that source call a script on the server that returns
          > javascript.
          > I did that approach for some dynamic content and put up a little thing about
          > it here.
          >
          > http://www.ipwebdesign.net/kaelisSpa...SelectsDB.html
          >[color=green]
          > > javascript functions that access only the current document. Are there any
          > > that access an arbitrary server (e.g. MySQL)[/color]
          >
          > No. Not exactly.
          > It has to call server-side script that does things.
          > Basically it's like a web service, kinda sorta. It just makes a request to a
          > web server. What the request does is up to you.
          >
          > --
          > --
          > ~kaeli~
          > Time flies like an arrow. Fruit flies like a banana.
          > http://www.ipwebdesign.net/wildAtHeart
          > http://www.ipwebdesign.net/kaelisSpace
          >
          >[/color]

          Comment

          Working...