473,411 Members | 2,059 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,411 software developers and data experts.

Script problem with Netscape 7

Hello all !

I need help with this script :
It's a tooltip appearing onMouseOver on a link. It works fine in IE, Opera
but not Netscape 7 and Mozilla 1.5.
The tooltip sticks on the top left corner of the window.

Any help appreciated :-)

Thanks

==================================
<script language="JavaScript" type="text/JavaScript">
<!--
function initToolTips(){
offsetX = 0;
offsetY = 15;
ns4 = document.layers;
ns6 = document.getElementById && !document.all;
ie4 = document.all;
toolTipSTYLE="";
if (ns4 || ns6 || ie4) {
if (ns4) toolTipSTYLE = document.toolTipLayer;
else if(ns6) toolTipSTYLE =
document.getElementById("toolTipLayer").style;
else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;
if (ns4) document.captureEvents(Event.MOUSEMOVE);
else {
toolTipSTYLE.visibility = "visible";
toolTipSTYLE.display = "none";
}
document.onmousemove = moveToMouseLoc;
}
}
//--------------------------
function moveToMouseLoc(e) {

if(ns4 || ns6) {
x = e.pageX; y = e.pageY;
} else {
x = event.x + document.body.scrollLeft;
y = event.y + document.body.scrollTop;
}
toolTipSTYLE.left = x + offsetX;
toolTipSTYLE.top = y + offsetY;
return true;
}
//--------------------------
function toolTip(valItal, valGras, msg, fg, bg, police, tailleTexte) {

if(toolTip.arguments.length < 1) { // hide

if (ns4) toolTipSTYLE.visibility = "hidden";
else toolTipSTYLE.display = "none";
} else { // show
var content =
'<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + fg +
'"><td>' +
'<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + bg +
'"><td align="center"><font face="'+ police +'" color="' + fg +
'" size="' + tailleTexte + '">&nbsp\;' + msg +
'&nbsp\;</font></td></table></td></table>';

if (ns4) {
toolTipSTYLE.document.write(content);
toolTipSTYLE.document.close();
toolTipSTYLE.visibility = "visible";
}
if (ns6) {
document.getElementById("toolTipLayer").innerHTML = content;
toolTipSTYLE.display='block'
}
if (ie4) {
document.all("toolTipLayer").innerHTML=content;
toolTipSTYLE.display='block'
}
}
}
//-->
</script>
</head>

<body>
<div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>

<script language="JavaScript">
<!--
initToolTips();
-->
</script>

<p>
<a href="javascript:;"
onMouseOver="toolTip('0','0','TEXT','#000000','#FF FFFF','Arial, Helvetica,
sans-serif','2')" onMouseOut="toolTip()">Test 1</a>
</p>

Jul 20 '05 #1
2 3075
"Phil" <pa*******@pasdemail.com> writes:
Hello all !

I need help with this script :
It's a tooltip appearing onMouseOver on a link. It works fine in IE, Opera
but not Netscape 7 and Mozilla 1.5.
The tooltip sticks on the top left corner of the window.

Any help appreciated :-) <script language="JavaScript" type="text/JavaScript">
The language attribut can be omitted
<!--
and so can this.


function initToolTips(){
offsetX = 0;
offsetY = 15;
ns4 = document.layers;
ns6 = document.getElementById && !document.all;
ie4 = document.all;
These five variables are global, and are used as such. I would
declare them outside the function to signal this.

Your variables suggests that only ie4 has a document.all property.
That is not true. Generally, browser detection is not a very stable
way of making the script compatible with other browsers.

Where does the values of the variables "offsetX" and "offsetY" come
from?
toolTipSTYLE="";
Since this variable is used to hold an object, I would initialize it
with null instead of the empty string.

All in all, I would use the following code instead:
---
var offsetX = 0;
var offsetY = 15;
var toolTipStyle;

function initToolTip() {
var toolTipElem;
if (document.getElementById) {
toolTipElem = document.getElementById("toolTipLayer");
} else if (document.all) {
toolTipElem = document.all["toolTipLayer"];
} else if (document.layers) {
toolTipElem = document.layers["toolTipLayer"];
}
if (!toolTipElem) {return;} // something wrong.
toolTipStyle = toolTipElem.style || toolTipElem;

toolTipStyle.visibility = "visible";
toolTipStyle.display = "none";

// listen to mouse move event
if (document.addEventListener) {
document.addEventListener("mousemove",moveToMouseL oc,false);
} else if (document.attachEvent) {
document.attachEvent("onmousemove",function(){
moveToMouseLoc(window.event);
});
} else {
document.onmousemove = moveToMouseLoc;
}
if (document.captureEvents && window.Event &&
window.Event.MOUSEMOVE) {
document.captureEvents(window.Event.MOUSEMOVE);
}
}
---
function moveToMouseLoc(e) {

if(ns4 || ns6) {
Here you assume something about the event from your guess at the
browser. If the guess is wrong, so is the result. That should not
be a problem for NS7/Mozilla, though.
x = e.pageX; y = e.pageY;
Make variables local if possible.
} else {
x = event.x + document.body.scrollLeft;
y = event.y + document.body.scrollTop;
If the browser is in standards mode (which all new pages *should* put
it), the scroll{Top,Left} values are placed on document.documentElement,
not document.body.
}
toolTipSTYLE.left = x + offsetX;
Probable cause of problem: You assign a CSS length without a unit. You
*must* add a unit, probably pixels ("px").
toolTipSTYLE.top = y + offsetY;
return true;
}
My suggested function
---
function moveToMouseLoc(event) {
var x,y;
if (typeof event.pageX == "number") {
x = event.pageX;
y = event.pageY;
} else {
var root = document.documentElement||document.body;
var x = event.clientX + root.scrollLeft;
var y = event.clientY + root.scrollTop;
}
toolTipStyle.left = (x+offsetX)+"px";
toolTipStyle.top = (y+offsetY)+"px";
}
---

<script language="JavaScript">
The *type* attribute is required in HTML 4.
Does your page validate?
<a href="javascript:;"


Avoid javascript:-URL's.
<URL:http://jibbering.com/faq/#FAQ4_24>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
> Does your page validate?

Don't think so :-)
In fact the whole code is a snippet coming from Dreamweaver...
I made some arrangements with global variables, because I can't have them
'global' for a future use

I will review all that.
Thanks a lot for your help and suggestions.
Jul 20 '05 #3

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

Similar topics

11
by: Jonny | last post by:
Netscape 7.02 is giving me a headache with a downloaded snow script. Starting with a blank page, I inserted the script and checked it in IE 6 and Netscape 7.02. Everything worked and looked fine. A...
4
by: Wm | last post by:
I have a script that changes a main/enlarged image when you click on a thumbnail. It works fine in IE, but for some reason it won't do anything in Netscape 7.1. Does anyone know if this is a...
5
by: zaw | last post by:
Hi I am working on implementing this script to shopping cart. Basically, it copies fill the shipping address from billing automatically. I believe one or more syntax is not netscape compatible....
7
by: Russ | last post by:
Hi All, I have a problem getting the following simple example of "document.write" creating a script on the fly to work in all html browsers. It works in I.E., Firefox, and Netscape 7 above. It...
9
by: Tuy Solang | last post by:
I download four scripts that are used to display Khmer PGN for Khmer Chess. It works fine with Netscape 7.1 on MS Millenium, but it gave me an error(Java Script console) with Netscape 8.1 on MS...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.