By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,528 Members | 1,345 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,528 IT Pros & Developers. It's quick & easy.

MouseEvent in Firefox 1.5 (2)

P: n/a
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.
Sep 12 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Robert wrote:
<button id="testButton" onclick="init();test2(event)">Firefox 1.5
MouseEvent test</button>


test2 must be test
Sep 12 '05 #2

P: n/a
ASM
Robert wrote:
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 ?
--
Stephane Moriaux et son [moins] vieux Mac
Sep 12 '05 #3

P: n/a
ASM wrote:
Robert wrote:
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.
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


Use tab to focus the button.
Sep 12 '05 #4

P: n/a


Robert wrote:
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.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 12 '05 #5

P: n/a
Martin Honnen wrote:


Robert wrote:
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;
});
}
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.
Sep 12 '05 #6

P: n/a
ASM
Robert wrote:
ASM wrote:
Robert wrote:
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.
Of course normally the init() function would do something useful.
When you click on the button in Firefox 1.0x,
FF 1.0.4 ==>
- alert : constructor is an event
- 2nd alert : null
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


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 ?

--
Stephane Moriaux et son [moins] vieux Mac
Sep 12 '05 #7

P: n/a
ASM
Martin Honnen wrote:
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]'

--
Stephane Moriaux et son [moins] vieux Mac
Sep 13 '05 #8

P: n/a


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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 13 '05 #9

P: n/a


Robert wrote:

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.


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?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 13 '05 #10

P: n/a
ASM wrote:
Robert wrote:
ASM wrote:
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.
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 ?


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.
Sep 16 '05 #11

P: n/a
Martin Honnen wrote:


Robert wrote:

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.

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.
Sep 16 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.