reading 'type' from eventhandlers | | |
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 | | | | re: reading 'type' from eventhandlers
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" <klynntg@hotmail.com> wrote in message news:5fb632c2.0309171210.7402fcca@posting.google.c om...[color=blue]
> 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[/color] | | | | re: reading 'type' from eventhandlers
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" <news@CsabaGabor.com> wrote in message news:<bkakau$fbq@dispatch.concentric.net>...[color=blue]
> 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" <klynntg@hotmail.com> wrote in message news:5fb632c2.0309171210.7402fcca@posting.google.c om...[color=green]
> > 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...[/color]
> doSomethingElse();[color=green]
> > }
> > }
> > // --></SCRIPT>
> >
> >
> > Thanks in advance for any help!
> >
> > Kathy Lynn[/color][/color] | | | | re: reading 'type' from eventhandlers
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" <klynntg@hotmail.com> wrote in message news:5fb632c2.0310060509.71271b69@posting.google.c om...[color=blue]
> 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" <news@CsabaGabor.com> wrote in message news:<bkakau$fbq@dispatch.concentric.net>...[color=green]
> > 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" <klynntg@hotmail.com> wrote in message[/color][/color]
news:5fb632c2.0309171210.7402fcca@posting.google.c om...[color=blue][color=green][color=darkred]
> > > 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...[/color]
> > doSomethingElse();[color=darkred]
> > > }
> > > }
> > > // --></SCRIPT>
> > >
> > >
> > > Thanks in advance for any help!
> > >
> > > Kathy Lynn[/color][/color][/color] |  | Similar JavaScript / Ajax / DHTML bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,374 network members.
|