Hi. Question. Say I have <a onclick=' return Outline(this)' onmouseover=' return Outline(this)'> . How could I determine in Outline() that it was launched from a mouseover, as opposed to onclick?
function call?
Collapse
This topic is closed.
X
X
-
Dennis AllenTags: None -
Dietmar Meier
Re: function call?
Dennis Allen wrote:
[color=blue]
> Hi. Question. Say I have <a onclick=' return Outline(this)'
> onmouseover=' return Outline(this)'> . How could I determine in
> Outline() that it was launched from a mouseover, as opposed to
> onclick?[/color]
function Outline(oElemen t, oEvent) {
var sType = oEvent && oEvent.type || "unknown";
alert(sType);
}
....
<a ...
onclick="return Outline(this, event)"
onmouseover="re turn Outline(this, event)"[color=blue]
>[/color]
ciao, dhgm
-
Evertjan.
Re: function call?
Dietmar Meier wrote on 06 feb 2005 in comp.lang.javas cript:[color=blue]
> <a ...
> onclick="return Outline(this, event)"
> onmouseover="re turn Outline(this, event)"[/color]
onclick="return Outline(this, 'onclick')"
onmouseover="re turn Outline(this, 'onmouseover')"
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
Comment
-
Dietmar Meier
Re: function call?
Evertjan. wrote:
[color=blue][color=green]
>> <a ...
>> onclick="return Outline(this, event)"
>> onmouseover="re turn Outline(this, event)"[/color][/color]
[color=blue]
> onclick="return Outline(this, 'onclick')"
> onmouseover="re turn Outline(this, 'onmouseover')"[/color]
That's no improvement at all.
ciao, dhgm
Comment
-
Evertjan.
Re: function call?
Dietmar Meier wrote on 06 feb 2005 in comp.lang.javas cript:
[color=blue]
> Evertjan. wrote:[color=green][color=darkred]
>>> <a ...
>>> onclick="return Outline(this, event)"
>>> onmouseover="re turn Outline(this, event)"[/color][/color]
>[color=green]
>> onclick="return Outline(this, 'onclick')"
>> onmouseover="re turn Outline(this, 'onmouseover')"[/color]
>
> That's no improvement at all.[/color]
I think it is. Simplicity usually wins.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
Comment
-
Ivo
Re: function call?
"Evertjan." wrote[color=blue]
> Dietmar Meier wrote[color=green]
> > Evertjan. wrote:[color=darkred]
> >>> onclick="return Outline(this, event)"
> >>> onmouseover="re turn Outline(this, event)"[/color]
> >[color=darkred]
> >> onclick="return Outline(this, 'onclick')"
> >> onmouseover="re turn Outline(this, 'onmouseover')"[/color]
> >
> > That's no improvement at all.[/color]
>
> I think it is. Simplicity usually wins.[/color]
Right, and passing the event with all event handlers is simpler than
hard-coding a different string with every mouseover, click and whathaveyou,
wouldn't you think?
--
Ivo
Comment
-
Evertjan.
Re: function call?
Ivo wrote on 06 feb 2005 in comp.lang.javas cript:[color=blue]
> "Evertjan." wrote[color=green]
>> Dietmar Meier wrote[color=darkred]
>> > Evertjan. wrote:
>> >>> onclick="return Outline(this, event)"
>> >>> onmouseover="re turn Outline(this, event)"
>> >
>> >> onclick="return Outline(this, 'onclick')"
>> >> onmouseover="re turn Outline(this, 'onmouseover')"
>> >
>> > That's no improvement at all.[/color]
>>
>> I think it is. Simplicity usually wins.[/color]
>
> Right, and passing the event with all event handlers is simpler than
> hard-coding a different string with every mouseover, click and
> whathaveyou, wouldn't you think?[/color]
No.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
Comment
-
Dietmar Meier
Re: function call?
Evertjan. wrote:
[color=blue][color=green][color=darkred]
>>>> onclick="return Outline(this, event)"
>>>> onmouseover="re turn Outline(this, event)"[/color][/color][/color]
[color=blue][color=green][color=darkred]
>>> onclick="return Outline(this, 'onclick')"
>>> onmouseover="re turn Outline(this, 'onmouseover')"[/color][/color][/color]
[color=blue][color=green]
>> That's no improvement at all.[/color][/color]
[color=blue]
> I think it is. Simplicity usually wins.[/color]
It's not "simple" to write down a string that's already present
as a property of the event object, nor is it "simple" to write
different code for different event handlers where a versatile
variant can be just copied&pasted.
Beyond that you make it harder to maintain: if I have a typo
like "return Outline(this, ebent)", I will most likely get an
error or exeption in this very line, e.g. telling me that there
is no such property. If you have a typo like "return Outline(
this, 'onclock')", you'll most likely get unexpected behaviour
in the function Outline(), thus not in the typo's place.
ciao, dhgm
Comment
-
eric
Re: function call?
How about something like:
<script>
function myfun(good,stuf f){
if (stuff.type=="c lick") theevent="click event"
if (stuff.type=="m ouseover") theevent="mouse over event"
alert(theevent)
}
</script>
<a id="fred" href="urlhere" onclick="myfun( this,event)"
onmouseover="my fun(this,event) " >Object stuff</a>
further details at:
Comment
-
eric
Re: function call?
How about something like:
<script>
function myfun(good,stuf f){
if (stuff.type=="c lick") theevent="click event"
if (stuff.type=="m ouseover") theevent="mouse over event"
alert(theevent)
}
</script>
<a id="fred" href="urlhere" onclick="myfun( this,event)"
onmouseover="my fun(this,event) " >Object stuff</a>
Comment
-
eric
Re: function call?
Hi,
Howabout something like this:
<script>
function myfun(good,stuf f){
if (stuff.type=="c lick") theevent="click event"
if (stuff.type=="m ouseover") theevent="mouse over event"
alert(theevent)
}
</script>
<a id="fred" href="urlhere" onclick="myfun( this,event)"
onmouseover="my fun(this,event) " >Object stuff</a>
For (lots of ) details and browser compatibility check out:
Comment
-
Dennis Allen
Re: function call?
I was hoping for a way that didn't involve passing another parameter, but it'll work...Dennis
"eric" <ericcremer@yah oo.com> wrote in message news:1107817797 .548584.201450@ l41g2000cwc.goo glegroups.com.. .[color=blue]
> Hi,
> Howabout something like this:
>
> <script>
> function myfun(good,stuf f){
> if (stuff.type=="c lick") theevent="click event"
> if (stuff.type=="m ouseover") theevent="mouse over event"
> alert(theevent)
> }
> </script>
>
> <a id="fred" href="urlhere" onclick="myfun( this,event)"
> onmouseover="my fun(this,event) " >Object stuff</a>
>
> For (lots of ) details and browser compatibility check out:
> http://www.webreference.com/js/column9/index.html
>[/color]
Comment
-
RobB
Re: function call?
Dennis Allen wrote:[color=blue]
> I was hoping for a way that didn't involve passing another parameter,[/color]
but it'll work...Dennis[color=blue]
>
> "eric" <ericcremer@yah oo.com> wrote in message[/color]
news:1107817797 .548584.201450@ l41g2000cwc.goo glegroups.com.. .[color=blue][color=green]
> > Hi,
> > Howabout something like this:
> >
> > <script>
> > function myfun(good,stuf f){
> > if (stuff.type=="c lick") theevent="click event"
> > if (stuff.type=="m ouseover") theevent="mouse over event"
> > alert(theevent)
> > }
> > </script>
> >
> > <a id="fred" href="urlhere" onclick="myfun( this,event)"
> > onmouseover="my fun(this,event) " >Object stuff</a>
> >
> > For (lots of ) details and browser compatibility check out:
> > http://www.webreference.com/js/column9/index.html
> >[/color][/color]
Just for the sake of argument....
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled </title>
<style type="text/css">
a {
width: 100px;
}
#t {
width: 100%;
height: 560px;
border: none;
font: 11px monospace;
}
</style>
<script type="text/javascript">
function Outline(e)
{
e = e || window.event;
if (e && (txt = document.getEle mentById('t')))
{
var p, c = [];
for (p in e)
c.push(p + ' ---> ' + e[p]);
txt.value = c.join('\n');
}
}
window.onload = function()
{
document.getEle mentById('t').v alue = '';
if (a = document.getEle mentsByTagName( 'a').item(0))
{
a.onmouseover = Outline;
a.onmouseout = Outline;
}
}
</script>
</head>
<body>
<a href="#">hoo-hah</a>
<textarea id="t"></textarea>
</body>
</html>
Comment
Comment