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="JavaS cript" type="text/JavaScript">
<!--
function initToolTips(){
offsetX = 0;
offsetY = 15;
ns4 = document.layers ;
ns6 = document.getEle mentById && !document.all;
ie4 = document.all;
toolTipSTYLE="" ;
if (ns4 || ns6 || ie4) {
if (ns4) toolTipSTYLE = document.toolTi pLayer;
else if(ns6) toolTipSTYLE =
document.getEle mentById("toolT ipLayer").style ;
else if(ie4) toolTipSTYLE = document.all.to olTipLayer.styl e;
if (ns4) document.captur eEvents(Event.M OUSEMOVE);
else {
toolTipSTYLE.vi sibility = "visible";
toolTipSTYLE.di splay = "none";
}
document.onmous emove = moveToMouseLoc;
}
}
//--------------------------
function moveToMouseLoc( e) {
if(ns4 || ns6) {
x = e.pageX; y = e.pageY;
} else {
x = event.x + document.body.s crollLeft;
y = event.y + document.body.s crollTop;
}
toolTipSTYLE.le ft = x + offsetX;
toolTipSTYLE.to p = y + offsetY;
return true;
}
//--------------------------
function toolTip(valItal , valGras, msg, fg, bg, police, tailleTexte) {
if(toolTip.argu ments.length < 1) { // hide
if (ns4) toolTipSTYLE.vi sibility = "hidden";
else toolTipSTYLE.di splay = "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 + '"> \;' + msg +
' \;</font></td></table></td></table>';
if (ns4) {
toolTipSTYLE.do cument.write(co ntent);
toolTipSTYLE.do cument.close();
toolTipSTYLE.vi sibility = "visible";
}
if (ns6) {
document.getEle mentById("toolT ipLayer").inner HTML = content;
toolTipSTYLE.di splay='block'
}
if (ie4) {
document.all("t oolTipLayer").i nnerHTML=conten t;
toolTipSTYLE.di splay='block'
}
}
}
//-->
</script>
</head>
<body>
<div id="toolTipLaye r" style="position :absolute; visibility: hidden"></div>
<script language="JavaS cript">
<!--
initToolTips();
-->
</script>
<p>
<a href="javascrip t:;"
onMouseOver="to olTip('0','0',' TEXT','#000000' ,'#FFFFFF','Ari al, Helvetica,
sans-serif','2')" onMouseOut="too lTip()">Test 1</a>
</p> 2 3097
"Phil" <pa*******@pasd email.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="JavaS cript" type="text/JavaScript">
The language attribut can be omitted
<!--
and so can this.
function initToolTips(){ offsetX = 0; offsetY = 15; ns4 = document.layers ; ns6 = document.getEle mentById && !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.getEl ementById) {
toolTipElem = document.getEle mentById("toolT ipLayer");
} else if (document.all) {
toolTipElem = document.all["toolTipLay er"];
} else if (document.layer s) {
toolTipElem = document.layers["toolTipLay er"];
}
if (!toolTipElem) {return;} // something wrong.
toolTipStyle = toolTipElem.sty le || toolTipElem;
toolTipStyle.vi sibility = "visible";
toolTipStyle.di splay = "none";
// listen to mouse move event
if (document.addEv entListener) {
document.addEve ntListener("mou semove",moveToM ouseLoc,false);
} else if (document.attac hEvent) {
document.attach Event("onmousem ove",function() {
moveToMouseLoc( window.event);
});
} else {
document.onmous emove = moveToMouseLoc;
}
if (document.captu reEvents && window.Event &&
window.Event.MO USEMOVE) {
document.captur eEvents(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.s crollLeft; y = event.y + document.body.s crollTop;
If the browser is in standards mode (which all new pages *should* put
it), the scroll{Top,Left } values are placed on document.docume ntElement,
not document.body.
} toolTipSTYLE.le ft = x + offsetX;
Probable cause of problem: You assign a CSS length without a unit. You
*must* add a unit, probably pixels ("px").
toolTipSTYLE.to p = 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.docume ntElement||docu ment.body;
var x = event.clientX + root.scrollLeft ;
var y = event.clientY + root.scrollTop;
}
toolTipStyle.le ft = (x+offsetX)+"px ";
toolTipStyle.to p = (y+offsetY)+"px ";
}
---
<script language="JavaS cript">
The *type* attribute is required in HTML 4.
Does your page validate?
<a href="javascrip t:;"
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/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
> 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 check on CPU
usage (Windows Task Manager>Performance) gave a 0% to 2% reading for
both browsers on a Pentium 4, 3.06GHz running XP.
As I added text, images, tiled background and so on. I noticed the
mouse was becoming jerky in Netscape 7....
|
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 problem with Netscape, or is
there something I can alter in this script that will allow it to work in
both IE and Netscape?
<script language="JavaScript">
function enlarge() {
oSrcElem = event.srcElement;
imgLarge.src =...
|
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. Can anyone point out which one it is and how to make it
both netscape and MS browser compatible? I hope if I can make the
script compatible for those two at extreme, it will probably work with
most browser out there. As you would notice, this form...
|
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 doesn't seem to work in Netscape 4. Am I missing
something with it? When I look at page source in
Netscape 4 the script isn't even shown.
Can Netscape 4 create scripts on the fly at all?
|
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 XP. Here is the line :
var pat_piece=/(\w{2}+)-(\w{2,3})/;
I am familiar with C, but I have no clue with the above expression.
Can someone help me to explain this expression?
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |