Is there a way to order which event handler is handled first?
If I have 2 event handlers listening for the onbeforeunload event, is there a way for one event handler wait until the other event handler is finished?
-Frinny
so in case it is not sure which handler is assigned first then how should the sequence be? ... the only way i could think of would be to let one handler set something and let the other wait with an interval ... if the 'set' didn't occur already then trigger the wished function first and then the next time the intentionally second handler would find the 'set' value ...
to the other question: you could ask if a node already has a handler assigned like: - var node = document.getElementById('foo');
-
-
if (typeof node.onclick == 'function') {
-
alert('node has a click-handler assigned');
-
}
kind regards,
gits
9 3419
I’m not exactly sure, but I think that the handlers are executed one after the other in order of their assignment (of course this doesn’t apply to IE)
gits 5,390
Expert Mod 4TB
as far as i'm aware it should be as Dormilich said ... but personally i wouldn't do such things ... i mean adding more then one handler in such a way ... just find it not 'defined' enough ... i would always prefer to chain them for myself ... so that i would have control of all that ... the way i always use is:
1. have a custom addListener(node, type, callback) method
2. this checks whether a specific type of listener is registered for the node already
3. then combines the callbacks in case one is present already
so i could always rely on the sequence of execution ...
kind regards
just find it not 'defined' enough ... i would always prefer to chain them for myself ...
The content is dynamically generated and it could be difficult to keep track of which handler was assigned first.
this checks whether a specific type of listener is registered for the node already
I'm not entirely sure how to approach this suggestion.
Any links or general ideas on how to accomplish this?
Thanks!
-Frinny
gits 5,390
Expert Mod 4TB
so in case it is not sure which handler is assigned first then how should the sequence be? ... the only way i could think of would be to let one handler set something and let the other wait with an interval ... if the 'set' didn't occur already then trigger the wished function first and then the next time the intentionally second handler would find the 'set' value ...
to the other question: you could ask if a node already has a handler assigned like: - var node = document.getElementById('foo');
-
-
if (typeof node.onclick == 'function') {
-
alert('node has a click-handler assigned');
-
}
kind regards,
gits
I'm going to try this: - if (typeof node.onclick == 'function') {
-
// do stuff
-
}
The reason I'm asking this question is because I have 2 methods that handle the onbeforeunload event. One method checks for changes made to the page and informs the user that if they leave the data provided so far will be lost (there's quite a bit of data to be entered on the page). The other method blocks the content while the page is sending a request to the server with a partially transparent <div> over top of everything and a "processing" message on top of that.
So, what happens is that the user is given the chance to cancel the unload event...but if they do the transparent div and processing message blocking the page prevent the user from accessing the page again.
Either I need to be able to tell when the user has cancelled the page unload or I need to be able to prevent the div and processing message from being displayed when the user is being informed of potential loss of work.
I don't think it's possible to tell when the user cancelled the page unload event so I'm trying to implement the second.
I think your suggestion will work for me :)
Thanks again!
-Frinny
Hmm, this apparently doesn't work: -
if(typeof window.onbeforeunload == 'function'){
-
alert('onbeforeunload handler already assigned');
-
}
gits 5,390
Expert Mod 4TB
it should ... here is a working example: - <html>
-
<script type="text/javascript">
-
function foo() {
-
if (typeof window.onbeforeunload == 'function') {
-
alert('foo');
-
}
-
}
-
-
window.onbeforeunload = function() {
-
};
-
</script>
-
<body onload="foo();">
-
</body>
-
</html>
-
could it be that the handler isn't added at this time?
Thanks Gits,
I tried testing it in a place where the window.onbeforeunload had not been assigned to a function yet. I moved typeof check into the function that is called to display the div and processing message and it works as I expected it to.
Thanks again :)
-Frinny
gits 5,390
Expert Mod 4TB
glad to hear that you got it working :)
kind regards,
gits
Sign in to post your reply or Sign up for a free account.
Similar topics
by: abs |
last post by:
My element:
<span onclick="alert('test')" id="mySpan">test</span>
Let's say that I don't know what is in this span's onclick event. Is it
possible to add another action to this element's onclick...
|
by: Ken Madden |
last post by:
I want to create multiple fileSystemWatchers in a Windows Service to
constantly watch multiple folders for file creations and then execute
certain code based on these actions. The problem is that...
|
by: Kamilche |
last post by:
'''
event.py
An event manager using publish/subscribe, and weakrefs.
Any function can publish any event without registering it first, and
any
object can register interest in any event, even...
|
by: Marek Murin |
last post by:
Hi all,
I have created vb.net user control that has to be used by vb6 form.
Everything goes well with putting the vb.net user control on the VB6 form
until I want to receive any event from my...
|
by: Eniac |
last post by:
Hello,
I've started using Enterprise Library 2.0 recently and I've encountered
a problem that seems to be ... well... undocumented :)
Basically, when I set a Trace Listener (formatted event...
|
by: MP |
last post by:
Hi
trying to begin to learn database using vb6, ado/adox, mdb format, sql
(not using access...just mdb format via ado)
i need to group the values of multiple fields
- get their possible...
|
by: nyc10011 |
last post by:
Does anyone know the proper syntax to insert (in the AS3 code below) so that additional flv's play sequentially from the same FLVPlybk component? ? I am trying to figure out how to incorporate AS3...
|
by: raylopez99 |
last post by:
Compound question: first, and this is not easy, if there's a way to
detect multiple simultaneous key presses in C# let me know (in the
below code, keys c and d being pressed simultaneously or...
|
by: Maric Michaud |
last post by:
Le Thursday 28 August 2008 03:43:16 norseman, vous avez écrit :
Disctionaries are hash tables with a unique key and constant time lookup. What
you want could be implemented as a complex data...
|
by: Composer |
last post by:
More experienced programmers may laugh that I had to struggle with
this, but I post it so that others in my position might benefit.
My application allows the user to have many forms open. Some...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
| |