reading 'type' from eventhandlers

  • Thread starter Catherine Lynn Smith
  • Start date
C

Catherine Lynn Smith

I'm looking through the client side javascript reference and there's
some mighty useful information in here, but it is not very specific on
'reading' information from event handlers.

In the interest of streamlining my scripting, I was thinking I could
write multi-purpose functions to handle mouseOver and mouseOut events.
Thus far, I am manually passing if it is an Over or Out event, but it
occurs to me that there might be a way to read status of an event
somewhere. Alas, the web is so full of 'simple' mouseOver and
mouseOut handling, I have not as of yet refined a search enough to get
to the information I need.

I tried just doing a test against the element event [
if(elementObject.onmouseover) { doThis(); } ] but that does not seem
to work. What I am looking for is something like:

<a href="somedoc.htm" onMouseOver="mouseEvent(this);"
onMouseOut="mouseEvent(this);">some link text</a>


<SCRIPT language="javascript"><!--
function mouseEvent(elementObject) {
if(elementObject.onmouseover) { // or whatever syntax to test
doSomething();
} else if(elementObject.onmouseout) { // again, whatever...
doSomethingElse();
}
}
// --></SCRIPT>


Thanks in advance for any help!

Kathy Lynn
 
C

Csaba2000

Hi Kathy (I note that Catherine starts with C),

If I understand you right, you are talking about
<a href="somedoc.htm" onMouseOver="mouseEvent(this,event);"
onMouseOut="mouseEvent(this,event);">some link text</a>

<SCRIPT type="text/javascript"><!--
function mouseEvent(elementObject, evt) {
var e = evt || window.event;
if (e.type == "mouseover") { // double check capitalization
doSomething();
} else if(e.type=="mouseout") { // again, whatever...
doSomethingElse();
}
}
// --></SCRIPT>

There have been several detailed discussions about these
types of events in the last few weeks. Perhaps do a google
search (in the groups tab) on
"Csaba Gabor" onmouseover
In particular, I recommend the two responses by
Lasse Reichstein Nielsen in the
..onmouseover=... syntax question re NN events
thread in this (comp.lang.javascript) newsgroup as being
an excellent, detailed coverage.

Csaba Gabor from New York

PS. The this / elementObject are not required in the code above.
I left them in to show the structure. Another way (shown in the
google examples) is with e.target || e.srcElement (but this is not
necessarily the same as what you get with this. For example,
if you mouse over #text in a TD with the TD's onmouseover
set, the tartget will be the #text but the elementObject (this)
will give you the TD).
 
C

Catherine Lynn Smith

OK, now I am running into a different situation that is sort of in the
same arena. I am going to trigger a setTimeout event from a onClick -
when it times out, I want to see if the person is still holding the
mouse down on that element. I assume the best way to do this would be
checking to see if a mouseDown event still exists in conjunction with
a mouseOver on the same object.

But I am still at a loss on the exact way to check if such events are
currently occuring nor how to check the mouseOver specific to that
element when the code that will be executed is spawned from the
timeout rather than an actual mouseOver.

Any help is appreciated. (even a RTFM that points me to a good source
for info)

KL

Csaba2000 said:
Hi Kathy (I note that Catherine starts with C),

If I understand you right, you are talking about
<a href="somedoc.htm" onMouseOver="mouseEvent(this,event);"
onMouseOut="mouseEvent(this,event);">some link text</a>

<SCRIPT type="text/javascript"><!--
function mouseEvent(elementObject, evt) {
var e = evt || window.event;
if (e.type == "mouseover") { // double check capitalization
doSomething();
} else if(e.type=="mouseout") { // again, whatever...
doSomethingElse();
}
}
// --></SCRIPT>

There have been several detailed discussions about these
types of events in the last few weeks. Perhaps do a google
search (in the groups tab) on
"Csaba Gabor" onmouseover
In particular, I recommend the two responses by
Lasse Reichstein Nielsen in the
.onmouseover=... syntax question re NN events
thread in this (comp.lang.javascript) newsgroup as being
an excellent, detailed coverage.

Csaba Gabor from New York

PS. The this / elementObject are not required in the code above.
I left them in to show the structure. Another way (shown in the
google examples) is with e.target || e.srcElement (but this is not
necessarily the same as what you get with this. For example,
if you mouse over #text in a TD with the TD's onmouseover
set, the tartget will be the #text but the elementObject (this)
will give you the TD).


Catherine Lynn Smith said:
I'm looking through the client side javascript reference and there's
some mighty useful information in here, but it is not very specific on
'reading' information from event handlers.

In the interest of streamlining my scripting, I was thinking I could
write multi-purpose functions to handle mouseOver and mouseOut events.
Thus far, I am manually passing if it is an Over or Out event, but it
occurs to me that there might be a way to read status of an event
somewhere. Alas, the web is so full of 'simple' mouseOver and
mouseOut handling, I have not as of yet refined a search enough to get
to the information I need.

I tried just doing a test against the element event [
if(elementObject.onmouseover) { doThis(); } ] but that does not seem
to work. What I am looking for is something like:

<a href="somedoc.htm" onMouseOver="mouseEvent(this);"
onMouseOut="mouseEvent(this);">some link text</a>


<SCRIPT language="javascript"><!--
function mouseEvent(elementObject) {
if(elementObject.onmouseover) { // or whatever syntax to test
doSomething();
} else if(elementObject.onmouseout) { // again, whatever... doSomethingElse();
}
}
// --></SCRIPT>


Thanks in advance for any help!

Kathy Lynn
 
C

Csaba2000

Hi Kathy,

I responding from memory here, so everything I write is more
suspect than usual. However, from my recollection, this is a
tough problem (read: I didn't solve it). In particular (and someone
please correct me where I'm wrong), you can't check mouse status
like you could check for the control, shift, or alt key status.

Now, you could keep track of the mouse being released by
document.onmouseup and checking the target event appropriately.
Unfortunately, this method can be faked out. If I remember right, in
IE if you drag off the screen and return, mouse status is lost in some
circumtstances (though I just checked with a google button and the
button remembered on IE 5.5/Win 2K) - to compensate you can
include a check for the mouse leaving the document. I think Netscape
is nicer about this, and Opera is really whacky. (The following search
on google Groups gives discusses some aspects of this:
"csaba gabor" opera onmouseout).

Please do post back if you get somewhere on this. I'll be most
interested to learn more on this topic.

Regards,
Csaba Gabor from New York


Catherine Lynn Smith said:
OK, now I am running into a different situation that is sort of in the
same arena. I am going to trigger a setTimeout event from a onClick -
when it times out, I want to see if the person is still holding the
mouse down on that element. I assume the best way to do this would be
checking to see if a mouseDown event still exists in conjunction with
a mouseOver on the same object.

But I am still at a loss on the exact way to check if such events are
currently occuring nor how to check the mouseOver specific to that
element when the code that will be executed is spawned from the
timeout rather than an actual mouseOver.

Any help is appreciated. (even a RTFM that points me to a good source
for info)

KL

Csaba2000 said:
Hi Kathy (I note that Catherine starts with C),

If I understand you right, you are talking about
<a href="somedoc.htm" onMouseOver="mouseEvent(this,event);"
onMouseOut="mouseEvent(this,event);">some link text</a>

<SCRIPT type="text/javascript"><!--
function mouseEvent(elementObject, evt) {
var e = evt || window.event;
if (e.type == "mouseover") { // double check capitalization
doSomething();
} else if(e.type=="mouseout") { // again, whatever...
doSomethingElse();
}
}
// --></SCRIPT>

There have been several detailed discussions about these
types of events in the last few weeks. Perhaps do a google
search (in the groups tab) on
"Csaba Gabor" onmouseover
In particular, I recommend the two responses by
Lasse Reichstein Nielsen in the
.onmouseover=... syntax question re NN events
thread in this (comp.lang.javascript) newsgroup as being
an excellent, detailed coverage.

Csaba Gabor from New York

PS. The this / elementObject are not required in the code above.
I left them in to show the structure. Another way (shown in the
google examples) is with e.target || e.srcElement (but this is not
necessarily the same as what you get with this. For example,
if you mouse over #text in a TD with the TD's onmouseover
set, the tartget will be the #text but the elementObject (this)
will give you the TD).


I'm looking through the client side javascript reference and there's
some mighty useful information in here, but it is not very specific on
'reading' information from event handlers.

In the interest of streamlining my scripting, I was thinking I could
write multi-purpose functions to handle mouseOver and mouseOut events.
Thus far, I am manually passing if it is an Over or Out event, but it
occurs to me that there might be a way to read status of an event
somewhere. Alas, the web is so full of 'simple' mouseOver and
mouseOut handling, I have not as of yet refined a search enough to get
to the information I need.

I tried just doing a test against the element event [
if(elementObject.onmouseover) { doThis(); } ] but that does not seem
to work. What I am looking for is something like:

<a href="somedoc.htm" onMouseOver="mouseEvent(this);"
onMouseOut="mouseEvent(this);">some link text</a>


<SCRIPT language="javascript"><!--
function mouseEvent(elementObject) {
if(elementObject.onmouseover) { // or whatever syntax to test
doSomething();
} else if(elementObject.onmouseout) { // again, whatever... doSomethingElse();
}
}
// --></SCRIPT>


Thanks in advance for any help!

Kathy Lynn
 

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

Forum statistics

Threads
474,002
Messages
2,570,260
Members
46,858
Latest member
FlorrieTuf

Latest Threads

Top