MouseEvent in Firefox 1.5 (2)

R

Robert

Hi,

My previous thread on this topic was too short on information so I I'll
try again. When I tried out Firefox 1.5 beta some of my javascript did
not work anymore. Here is some code to illustrate the different
behaviour between Firefox 1.0x and 1.5.

function init()
{
Event.prototype.__defineGetter__("srcElement", function()
{
if (this.constructor == Event)
alert("Constructor is an event");
else
{
alert("Constructor is NOT an event");
alert(this.constructor);
}
return null;
});
}

function test(event)
{
alert(event.srcElement);
}

<button id="testButton" onclick="init();test2(event)">Firefox 1.5
MouseEvent test</button>

Of course normally the init() function would do something useful.
When you click on the button in Firefox 1.0x, the if statement
(this.constructor == Event) returns true. In Firefox 1.5 it returns
false and the alert shows "MouseEvent". It also shows "MouseEvent" when
you use the enter key to 'click' on the button.

So I was wondering why this change was made and if there is still a
possibility if this.constructor can be tested to see if it is some event
(it does not matter to me if it is a MouseEvent or whatever other kind
of Event). I tried to look at the prototype chain of the MouseEvent
hoping that the Event would be in the chain, but it just shows as a
native object.

Okay I hope this was more clear.

Robert.
 
A

ASM

Robert said:
Here is some code to illustrate the different
behaviour between Firefox 1.0x and 1.5.

[some JS code]
Of course normally the init() function would do something useful.
When you click on the button in Firefox 1.0x,

FF 1.0.4 ==> Error : test2 is not defined
In Firefox 1.5 it also shows "MouseEvent" when
you use the enter key to 'click' on the button.

How do I do that ?
I have anything to give focus to the form
Okay I hope this was more clear.

Huu ?
 
R

Robert

ASM said:
Robert said:
Here is some code to illustrate the different behaviour between
Firefox 1.0x and 1.5.


[some JS code]
Of course normally the init() function would do something useful.
When you click on the button in Firefox 1.0x,


FF 1.0.4 ==> Error : test2 is not defined

I made a mistake. It must be test of course.
How do I do that ?
I have anything to give focus to the form

Use tab to focus the button.
 
M

Martin Honnen

Robert said:
Here is some code to illustrate the different
behaviour between Firefox 1.0x and 1.5.

function init()
{
Event.prototype.__defineGetter__("srcElement", function()
{
if (this.constructor == Event)
alert("Constructor is an event");
else
{
alert("Constructor is NOT an event");
alert(this.constructor);
}
return null;
});
}

function test(event)
{
alert(event.srcElement);
}

<button id="testButton" onclick="init();test2(event)">Firefox 1.5
MouseEvent test</button>

Of course normally the init() function would do something useful.
When you click on the button in Firefox 1.0x, the if statement
(this.constructor == Event) returns true. In Firefox 1.5 it returns
false and the alert shows "MouseEvent". It also shows "MouseEvent" when
you use the enter key to 'click' on the button.

So I was wondering why this change was made and if there is still a
possibility if this.constructor can be tested to see if it is some event

I don't know why you need this check of the constructor. What case in
what browser do you expect that you need such a check?
And I can't tell without searching bugzilla why that change was made but
it will be difficult I think to argue it is a bug as the click event is
a MouseEvent.
The following test case however
<http://home.arcor.de/martin.honnen/javascript/2005/09/test2005091201.html>
shows that it is possible to use instanceof to do a check for the type.

At least with Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b4)
Gecko/20050912 Firefox/1.4 I get

srcElement getter:
this: [object MouseEvent]
this.type: click
this instanceof Event: true
this instanceof MouseEvent: true

when clicking the button and with Mozilla/5.0 (Windows; U; Windows NT
5.1; en-US; rv:1.7.11) Gecko/20050728 I get

srcElement getter:
this: [object Event]
this.type: click
this instanceof Event: true
this instanceof MouseEvent: true

so checking
instanceof Event
should work with Firefox 1.0.x and Firefox 1.5 Beta.


Of course instanceof is a problem if you still expect Netscape 4 users
to see your script. Not sure whether there is a solution to deal with
both, please try to explain why you think you need that constructor
check at all.
 
R

Robert

Martin said:
I don't know why you need this check of the constructor. What case in
what browser do you expect that you need such a check?

It is only needed for firefox in this case.
The following test case however
<http://home.arcor.de/martin.honnen/javascript/2005/09/test2005091201.html>
shows that it is possible to use instanceof to do a check for the type.

Ahh didn't know I could use instanceof too. Somehow I forgot! Thanks for
reminding me!

Of course instanceof is a problem if you still expect Netscape 4 users
to see your script. Not sure whether there is a solution to deal with
both, please try to explain why you think you need that constructor
check at all.

I just need it for firefox. This check was recommended to me by someone
on this newsgroup for defensive programming.
 
A

ASM

Robert said:
ASM said:
Robert said:
Here is some code to illustrate the different behaviour between
Firefox 1.0x and 1.5.

[some JS code]

I made a mistake. It must be test of course.

FF 1.0.4 ==>
- alert : constructor is an event
- 2nd alert : null
Use tab to focus the button.

That doesn't work with my Mac FF
Focus jumps form location bar to google bar to document and re begins
button gets never focus
Doesn't it need a tabindex ?
 
A

ASM

Martin said:
The following test case however
<http://home.arcor.de/martin.honnen/javascript/2005/09/test2005091201.html>
shows that it is possible to use instanceof to do a check for the type.

Of course instanceof is a problem if you still expect Netscape 4 users
to see your script.

Not only ...
this test doesn't work with my :
- Ie 5.2 mac : line20, car 50, error ')' waited
-> '(this instanceof Event)'
- Opera 8.01 : answer (innerhtml) only
'srcElement: [object HTMLInputElement]'
- Safari :
'srcElement: [object INPUT]'
- iCab 3.0 :
'srcElement: [object HTMLInputElement]'
 
M

Martin Honnen

ASM wrote:

this test doesn't work with my :
- Ie 5.2 mac : line20, car 50, error ')' waited
-> '(this instanceof Event)'

I mentioned Netscape 4 as one example where instanceof causes an error.
There are others, right.

- Opera 8.01 : answer (innerhtml) only
'srcElement: [object HTMLInputElement]'
- Safari :
'srcElement: [object INPUT]'
- iCab 3.0 :
'srcElement: [object HTMLInputElement]'

It is only a test case to show the original poster how to use a getter
to extent Event respectively Event.prototype in Mozilla browsers and how
to perhaps solve the problem the original poster has with different
Firefox versions.

Are you saying you get script errors (for instanceof use for example)
with the test case in Opera 8, Safari, and iCab 3.0? If they simply
display what you show there then I don't think there is anything wrong,
those browsers have made their own effort to provide the srcElement.
 
M

Martin Honnen

Robert wrote:

It is only needed for firefox in this case.

But what do you think could happen in Firefox that such a check is
needed and helpful? If you extend Event.prototype why do you think that
the this object could not be an event object?
 
R

Robert

ASM said:
Robert said:
ASM said:
Robert wrote:

Here is some code to illustrate the different behaviour between
Firefox 1.0x and 1.5.


[some JS code]
FF 1.0.4 ==>
- alert : constructor is an event
- 2nd alert : null

That's good.
That doesn't work with my Mac FF
Focus jumps form location bar to google bar to document and re begins
button gets never focus
Doesn't it need a tabindex ?

The tabindex attribute is implied when not specified. It will get a
tabindex that allows you to tab through the elements in the order that
they are in the source.

Sad to hear that FF did not implement it for the Mac.
 
R

Robert

Martin said:
Robert wrote:




But what do you think could happen in Firefox that such a check is
needed and helpful? If you extend Event.prototype why do you think that
the this object could not be an event object?

It's a good question, but I really don't know.
Maybe it is not possible.
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top