473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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
Jul 23 '05 #1
4 1388
In article <Pi*******************************@seawolf.cdf>,
c4******@cdf.toronto.edu enlightened us with...

So I was wondering can a custom event handler be implemented in javascript
Javascript runs on the client. And only the client.
(excepting jscript.net)
such that when some event happens elsewhere, not on the client, my
handler will catch it and perform the required operation?


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.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
Ok I got it but there is one more thing then I have a follow-up question.
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.


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
Jul 23 '05 #3
In article <Pi*******************************@seawolf.cdf>,
c4******@cdf.toronto.edu enlightened us with...
I know how to do
the timing but how would I contact the server?
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
javascript functions that access only the current document. Are there any
that access an arbitrary server (e.g. MySQL)


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

Jul 23 '05 #4
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:
In article <Pi*******************************@seawolf.cdf>,
c4******@cdf.toronto.edu enlightened us with...
I know how to do
the timing but how would I contact the server?


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
javascript functions that access only the current document. Are there any
that access an arbitrary server (e.g. MySQL)


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

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bo Dudek | last post by:
Hi I have this thought, that I'd like to share: Sometimes I'm using javascript in my webpages to create different kind of form-interactions. Sometimes I have an inputfield, and in this field...
3
by: Kiyomi | last post by:
Hello, I create a Table1 dynamically at run time, and at the same time, I would like to create LinkButton controls, also dynamically, and insert them into each line in my Table1. I would...
3
by: Robert | last post by:
I need some assistance doing some "right way to do it" coding. The following are EventHandlers associated with Delegates in a child form that call a procedure in the MDI form that resets a timer....
1
by: Johan Åhlén | last post by:
Hi, Does anybody have any idea how to access child nodes in a TreeView without using postbacks? For example: in the subtree below I want to disable nodes B, C and D when A is checked (and...
5
by: | last post by:
Hi all, Has anyone been able to write some custom javascript on the onclick event of submit button to do certain things like disable submit button, only submit form once etc. This was a breeze...
1
by: Pavan | last post by:
Hi All, I have created a custom DataList web custom control, which populates data from a dataset. This dataset is available at runtime and exposed as property by my custom control. During...
3
by: Armin | last post by:
Hello I have a UserControl with a Click Event. Is it possible to find out the List of all Delegates/Eventhandlers using the Event. I read something about a "getinvocationlist" Methode for...
1
by: Kasper Birch Olsen | last post by:
Hi NG Im adding a bunch of linkbuttons to a page, in a for loop, but I cant get the eventhandlers to work. A simplyfied version of the code looks like this: for (int i = 0; i<10; i++) {...
11
by: Faisal Vali | last post by:
Hi - I'm new to javascript and I was reading the book Javascript Professional Projects - there is a fragment that has me a little perplexed, and I was wondering if anyone could explain why and how...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.