473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Firefox compatibility

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;
}


Feb 4 '07 #1
2 1836
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?
>
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.

DOM:element.addEventListener
http://developer.mozilla.org/en/docs/addEventListener
>
//
// MENU'
//

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

function popup (who) {
popText0.style.visibility = "hidden";
When you want to get access to a particular element, you must refer to
it via one of the DOM 2 methods and not just by its name attribute value
or just by its id attribute value.

This mistake is very frequent. See:

Accessing Elements with the W3C DOM
http://developer.mozilla.org/en/docs...th_the_W3C_DOM

Also

Comp.lang.javascript FAQ
Why doesn't the global variable "divId" always refer to the element with
id="divId"?
http://jibbering.com/faq/#FAQ4_41

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");
Using eval() is 99% of the time wrong.

Comp.lang.javascript FAQ
When should I use eval?
http://jibbering.com/faq/#FAQ4_40

Also, here you are trying to position an element without defining its
unit creates a CSS parsing error.
CSS 1 and CSS 2.x specifications require that non-zero values must be
specified with a length unit; otherwise, the css declaration will be
ignored. Mozilla-based browsers, MSIE 6+, Opera 7+ and other W3C
standards-compliant browsers enforce such handling of parsing error.
CSS 1 Forward-compatible parsing
http://www.w3.org/TR/REC-CSS1#forwar...atible-parsing
CSS 2.1 Rules for handling parsing errors
http://www.w3.org/TR/CSS21/syndata.html#parsing-errors

Gérard
--
Using Web Standards in your Web Pages (Updated Dec. 2006)
http://developer.mozilla.org/en/docs...your_Web_Pages
Feb 4 '07 #2
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
Feb 4 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Niels | last post by:
Hi group, I have some problems with clearing floated divs. My usual method works fine in Konqueror, but not in Firefox. Here's an example: <html><body> <div id='left' style='float:left;...
15
by: 50295 | last post by:
Hi everyone, This one is better experienced than explained, so I'm including a code sample below. Please and save (as an html file) and view with NN or Firefox (or maybe even Mozilla), and then...
36
by: Simon Wigzell | last post by:
I have the following in my webpage: <body onresize=CenterIt(); onMouseMove=mouseCheck(event);> CenterIt and mouseCheck are my own javascript functions. Works fine for IE and Opera, doesn't...
4
by: fcurvat | last post by:
Hello, I've got a little problem with <script></script> under firefox 1.0.7 If the script is not placed in the body tag, it isn't automaticaly executed, but it is under Internet Explorer. ...
5
by: BJ | last post by:
Hi, I add label and text box fields dynamically in code using C# and ASP.NET. I set the width of the label using: Label label = new Label(); label.Width = 20; label.Text = "Test";...
45
by: Pat | last post by:
its seems asp.net validation doesn't fire when using FireFox? Tested a page and it doesn't fire. It seems the javascript doesn't fire Any ideas?
1
by: newspost2000 | last post by:
If anyone could help me out here. I am the webmaster of the following corporate website: http://www.otpp.com/. When I load this page in IE or Netscape for PC the postion of all of the elements on...
3
by: VK | last post by:
A minor Firefox update was released (now 1.5.0.1) Full list of fixes can be found here: <http://www.mozilla.com/firefox/releases/1.5.0.1.html> Unfortunately the same update bans Venkman for...
10
by: Paul Gorodyansky | last post by:
Hi, Ran into the problem today - in INPUT field Firefox executes clean-yp of the content if a user presses Esc, _before_ control goes to the code via onkeydown - and search showed that it's a...
5
by: Charlie | last post by:
Hi: I have some Custom server controls (validated textboxes) in a panel on a form. In Firefox, it looks all hosed up. Also, pictures show place holders while loading. What are my options for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.