Hi,
Gérard Talbot wrote:
> Serena wrote :
>> I have a problem whit this script. It is compatible with IE but isn't
>> with Firefox.
>>
>> The error are:
>> 1) "e has no properties" at-----> "if(e.pageX || e.pageY) {"
>> 2) "document.getElementById()" at------>
>> "popText0.style.visibility="visible"
>> Help me please
>> Serena
>>
>> //
>> // MOUSE position
>> //
>>
>> var posX = 0;
>> var posY = 0;
>>
>> function setPos () {
>> posX = 0;
>> posY = 0;
>
> posX and posY were set to 0 globally. Why do they need to be reset
> again, and this time, locally?
Because they are global. Further in the function they are set to a
value. Since we don't know when (and how often) the function will be
called, resetting them to 0 might be necessary.
The code could be much more modular, object-oriented, and that would
remove the need for global variable.
>> if (!e)
>> var e = window.event
>
> This will fail in Firefox and other DOM 2 event interface compliant
> browsers. event is not a properties of the window.
> You need to register an event listener on the targeted object.
That's probably what she did somewhere in the code which she doesn't
show us. For example, if you have
document.onload = setPos;
then you should declare the function like this:
function setPos( e )
{
...
}
Mozilla-based browsers pass the event details to the function when the
event handler is called. I always found this way of doing confusing and
for once prefer the IE way.
Maybe a better way is to go the other way round:
function setPos( e )
{
if ( window.event )
{
e = window.event;
}
if ( !e )
{
throw "Unknow platform";
}
}
HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog:
http://www.galasoft-LB.ch
PhotoAlbum:
http://www.galasoft-LB.ch/pictures
Support children in Calcutta:
http://www.calcutta-espoir.ch