New event listeners without disturbing old?

O

optimistx

I try to develope a bookmarklet, which hopefully can be activated on almost
any http-page (i.e. from any server).
The page can have unknown event handlers.
The bookmarklet wants to add its own event handlers for the page without
unnecessarily disturbing the original ones.

The problem resembles the onload-event handling: if there is already one how
to add another so that both handllers can do their work? ( this problem can
be solved , but in this case this is not the problem.

When playing with the FORK-framework some events could work without
disturbing each other, but some other events obviously did not: if e.g.
there was originally defined a 'click'-handler for the body and the
bookmarklet defined its own for the same event, the original might stop
working.

Is there an easy way to solve this problem generally, without knowing how
the original events are handled?

The problem is more or less fun and hobby, not to be taken very seriously.
Hopefully this would be fun for you too :).
 
G

Gregor Kofler

optimistx meinte:
Is there an easy way to solve this problem generally, without knowing how
the original events are handled?

What's wrong with addEventListener/attachEvent?

Gregor
 
O

optimistx

Gregor said:
optimistx meinte:


What's wrong with addEventListener/attachEvent?

Gregor
Good question! Nothing is wrong with them, but are they supposed not to
prevent previously defined ('original') events from being handled? Might be
that in my hasty preliminary tests some other things were disturbing the
situation. (Also an embarrassinging error happened: I had two event handling
functions on the same page with the same name... no wonder one of them
stopped working.)
This situation is like loading several different frameworks to the same
page and hoping everyone of them would continue behaving nicely.
 
G

Gregor Kofler

optimistx meinte:
Gregor Kofler wrote:
Good question! Nothing is wrong with them, but are they supposed not to
prevent previously defined ('original') events from being handled?

The *events* are always the same. And those methods are there, that
several *listeners* can peacefully co-exist.
This situation is like loading several different frameworks to the same
page and hoping everyone of them would continue behaving nicely.

Depends on the frameworks. But "normally" they can be combined without
too many problems. At least as fas as event listening goes.

Gregor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,169
Latest member
ArturoOlne
Top