Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Firefox compatibility

Reply
Thread Tools

Firefox compatibility

 
 
Serena
Guest
Posts: n/a
 
      02-04-2007
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;

if (!e)
var e = window.event

if (e.pageX || e.pageY) {
posX = e.pageX
posY = e.pageY
}

else if (e.clientX || e.clientY) {
posX = e.clientX + document.body.scrollLeft
posY = e.clientY + document.body.scrollTop
}

return
}

document.onmousemove = setPos;


//
// MENU'
//

var popShow = new Array (false, false, false);

function popup (who) {
popText0.style.visibility = "hidden";
popText1.style.visibility = "hidden";
popText2.style.visibility = "hidden";

topbutton0.style.visibility = "visible";
topbutton1.style.visibility = "visible";
topbutton2.style.visibility = "visible";


if (!popShow[who]) {
if (( who == 0 ) || ( who == 1 ))
{
eval("popText"+who+".style.left = posX + 10");
eval("popText"+who+".style.top = -38");
}
else
{
eval("popText"+who+".style.left = posX + 10");
eval("popText"+who+".style.top = -38");
}
eval("popText"+who+".style.visibility = \"visible\"");

for(var count in popShow)
popShow[count] = false;

popShow[who] = true;
eval("topbutton"+who+".style.visibility='hidden'") ;
}
else
popShow[who] = false;

return;
}




 
Reply With Quote
 
 
 
 
Laurent Bugnion [MVP]
Guest
Posts: n/a
 
      02-04-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mozilla/firefox website compatibility testing Séverine Firefox 1 03-29-2006 03:05 PM
Help with Firefox compatibility Craig Keightley Javascript 5 08-18-2005 02:49 PM
Mozilla Firefox compatibility problem Simon Wigzell Javascript 36 07-20-2005 02:53 PM
Firefox Compatibility with dynamically added labels? =?Utf-8?B?Qko=?= ASP .Net 5 06-14-2005 05:13 AM
Yahoo pledges full Firefox compatibility someone Firefox 2 03-21-2005 03:01 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57