 |
 |
Help With Javascript Errors In Firefox
|
 |
|
 |
|
Forum Regular
Join Date: Apr 2003
Location: Toronto, Canada
Status:
Offline
|
|
My site uses a dhtml tooltip script to pop-up information about certain links.
However, this script fails in Firefox, and I'm not entirely sure why.
If you have the Web Developer plugin for Firefox you'll see that it generates the following error twice:
Code:
tipobj has no properties
Once for line 32 and once for line 86 (of the script).
You can view the script at: http://www.benlewis.ca/blog/wp-style/tt.js
You can view the site at: http://www.benlewis.ca/blog/
If you want to see what the tooltips look like, use Safari or Internet Explorer. The script seems to work in both those browsers.
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Nov 1999
Status:
Offline
|
|
My guess is that your use of document.all confuses it. In one of the most supremely boneheaded moves which that team has ever done, they added document.all support but didn't make it detectable. They should have just left it out completely.
Ditch document.all and use the real standard -document.getElementById- everywhere. You stand to gain more users than you lose, given that document.getElementById is supported by IE5+ as well as Gecko.
|
|
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Apr 2003
Location: Toronto, Canada
Status:
Offline
|
|
Thanks for the quick reply Millenium.
I tried replacing document.all with document.getElementById but that didn't seem to work for Firefox and also broke the tooltips in Safari.
Now, perhaps this is just because I searched for and replaced all instances of document.all with document.getElementById and did nothing further.
Thing is, I'm only capable of hacking at the little pieces of javascript I understand, and that isn't very much.
Could you be more specific as to what I should change? Or perhaps someone could provide a proper edit of the code? Here is a clipping that contains all the instances of document.all"
Code:
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""
Of course any other ideas or suggestions are very much welcome.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Apr 2003
Location: Toronto, Canada
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status:
Offline
|
|
As Millennium mentioned, if you're only targeting IE5+ on the Win/IE side, then there's no need for the document.all stuff.
A few points:
• Make sure you're calling this after the page has loaded (onload) or at least after the elements you're targeting have been loaded. Otherwise, you'll get null, since the elements don't yet exist.
• The if statement you have only targets the next line, since there are no braces. Use if () {//code}
• It's not essential in javascript, but it's good practice to put semicolons at the end of lines, except for multi-line statement condition bits. (That probably makes no sense, sorry).
If I'm honest, I'd forget the browser checking code in that and just go the W3C DOM way...
Code:
var enabletip=false;
var tipobj=document.getElementById("dhtmltooltip");
var pointerobj=document.getElementById("dhtmlpointer");
Not the best way if you're planning on targeting as many browsers as possible, but the ones that don't support the above are few and far between nowadays.
(Last edited by Black Book; Mar 2, 2005 at 04:23 AM.
)
|
|
Just who are Britain? What do they? Who is them? And why?
Formerly Black Book
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Apr 2003
Location: Toronto, Canada
Status:
Offline
|
|
Okay, so I had missed the part of the instruction for the script that said to include it in the body. Since the rest of my scripts were called in the head I figured that's where this one belonged. Having moved the script call to the body of the page, everything works!
Thanks for all your help!
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status:
Offline
|
|
Originally posted by bwahahax:
Okay, so I had missed the part of the instruction for the script that said to include it in the body. Since the rest of my scripts were called in the head I figured that's where this one belonged. Having moved the script call to the body of the page, everything works!
Thanks for all your help!
Just so you know, that problem occured because you can't insert an element (using document.write) into the HEAD section of an HTML page and have it recognised as part of the document structure - it does need to happen inside the BODY section. That's why Firefox complained it couldn't find your tooltip DIV.
|
|
Computer thez nohhh...
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|