473,386 Members | 1,694 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,386 software developers and data experts.

JS works in IE but not FF

I've seen numerous iterations of this problem, but none of the proposed solutions work for me. When I use getElementsByTag() on an XML document, IE returns 2 hits but FF returns 0. I'll post both the loading function and relevant functions:

[PHP]function loadXML(){
// code for IE
if (window.ActiveXObject){
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("twl.xml");
oddBrowser=false;
setupTeam();
}

// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation &&
document.implementation.createDocument){
oddBrowser = true;
xmlDoc=document.implementation.createDocument(""," ",null);
xmlDoc.load("twl.xml");
xmlDoc.onload = setupTeam();
}
else
{
alert('Your browser cannot handle this script');
}
}[/PHP]
[PHP]function setupTeam(){ //Fails in FF
debugit('Entered Team Setup')
var name;
var url;
name = getChild(xmlDoc,"name");
debugit('Name: ' + name);
url = getChild(xmlDoc,"url");
debugit('URL: ' + url);

strOut += "<tr><td>" + "<a href=\"" + url + "\">" + name + "\
</a></td></tr>";

setupLadders();
}[/PHP]
[PHP]function getChild(cNode,target){
var retNode;
debugit('cNode: ' + cNode.nodeName + ' Target: ' + target);
var numTgts = cNode.getElementsByTagName(target).length;
debugit('Number of \"' + target + '\"s in ' + cNode.nodeName + ': ' + numTgts);
var i = 0;
do{
debugit('Entered do loop');
retNode = cNode.getElementsByTagName(target)[0].childNodes[i];
debugit('Current retNode value: ' + retNode.nodeValue);
i++;
}while(retNode.nodeType!=3)
debugit('retNode: ' + retNode.nodeName);
return retNode.nodeValue;
}[/PHP]

I get to the getElementsByTagName(target)[0] and FF's error console says that it has no properties (I'm assuming because it doesn't exist). I'm not sure what is wrong. The only other thing is that this is all being done locally, with the HTML file and XML file loaded into a directory on my HDD. I run the script by viewing the HTML page locally.
May 22 '07 #1
7 2614
acoder
16,027 Expert Mod 8TB
Try running on a web server or even localhost.
May 22 '07 #2
Unfortunately, when I ran it on a web server, I got the same results. :-(
May 22 '07 #3
pbmods
5,821 Expert 4TB
I get to the getElementsByTagName(target)[0] and FF's error console says that it has no properties (I'm assuming because it doesn't exist). I'm not sure what is wrong.
Does it fail regardless of the value of target, or are there certain targets that it won't find?

Is it a case-sensitivity issue? Try adding some '.toUpperCase()'s in there....
May 23 '07 #4
The value passed as target is always exact case to the node name (everything is lowercase in the XML document). Heh, this is very frustrating.
May 24 '07 #5
acoder
16,027 Expert Mod 8TB
What does the XML file look like?

xmlDoc is global (clutching at straws maybe?)
May 24 '07 #6
The XML file used (this program will actually be a Google Gadget, so I can take care of pulling an XML file off another domain without sever-side scripting) is hosted at another domain. I'm hoping to eventually use it for any team, but ours is located at http://www.teamwarfare.com/xml/viewt...ket+Clan%5D%5B.

xmlDoc is declared globally.

Thanks so much for being so thorough.
May 24 '07 #7
I canned the modularity I was going for and wrote it inline. I'm going to post the script (It's not terribly long and commented fairly well). It works exactly as planned in IE but not FF. The whole point of the getChild() function was based on faulty understanding of Mozilla's implimentation of the DOM (I thought there could be whitespace nodes between an element and its text, but it only happens between an element and its child if the child is another element). Anyway:

[PHP] var response;

function run(){
//Load code for IE
if (window.ActiveXObject){
response=new ActiveXObject("Microsoft.XMLDOM");
response.async=false;
response.load("twl.xml");
oddBrowser=false;
}
//Code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument){
alert('Mozilla Mode');
response=document.implementation.createDocument("" ,"",null);
response.load("twl.xml");
}
else{
alert('Your browser cannot handle this script');
}

// Start building HTML string that will be displayed in <div>.
var html ="<table border=\"1\">";
var i = 0;

//Get team name
var name;
name = response.getElementsByTagName('name')[0].firstChild.nodeValue;

//Get team URL
var teamurl;
teamurl = response.getElementsByTagName('url')[0].firstChild.nodeValue;

//Output Team Info
html += "<tr><td>" + "<a href=\"" + teamurl + "\">" + name + "</a></td></tr>";

//Setup Laddrs
var ladders;
var maps;
var ladderName;
var opp;
var date;
var map;

//Set Ladders and Maps nodeList
ladders = response.getElementsByTagName('ladder')
maps = response.getElementsByTagName('map');

//Loop through each ladder
for (var i=0; i<ladders.length; i++){
//Get Opponent Name
opp = ladders[i].getElementsByTagName('opponentname')[0].firstChild.nodeValue;

//Get Match Date
date = ladders[i].getElementsByTagName('matchdate')[0].firstChild.nodeValue;

//Map
map=maps.item(i*2).attributes[0].nodeValue;

//Ladder Name
ladderName=ladders.item(i).attributes[0].nodeValue;

html += "<tr><td><table border=\"2\">"
html += "<tr><td>Ladder</td><td>" + ladderName + "</td></tr>";
html += "<tr><td>Date/Time</td><td>" + date + "</td></tr>";
html += "<tr><td>Opponent</td><td>" + opp + "</td></tr>";
html += "<tr><td>Map</td><td>" + map + "</td></tr>"
html += "</table></td></tr>";
}

// Close up Table and div
html += "</table>";
html += "</div>";
document.write(html);
}[/PHP]

Once again, thanks for your time and dedication, I owe you a lot.
May 24 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Puneet Jain | last post by:
I am tryin to use Microsoft Works Wordprocessor from Python After generating the .py module from the type library using makepy utility, I runt he following commands, >>> from win32com.client...
1
by: Gerd Güldenast | last post by:
Hi, I am having a problem with a replication over a Modem-Connection, which works fine over LAN. Has anyone experienced this problem before? Settings are: 2 SQL Servers 2000, SP3 on Windows...
10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
1
by: Moi | last post by:
I have tried repeatedly to import a MS Works database (simple address database) into Access, but I am having little luck. I have saved the Works file as DbaseIII DbaseIV and neither is seen by the...
2
by: Enrique Bustamante | last post by:
Casting arrays that works on watch and command window but not in code. My application is casting arrays in a way it should work. To test if I was doing something invalid, I wrote a test code that...
4
by: puja | last post by:
hi all, I have an asp.net website where am including .css file dynamically on page load event. For diff users, there is diff CSS file. So after user logs in, I am setting CSS href on page load....
0
by: patmg | last post by:
Hello, We use a SQL Server database to manage accounts in AD via a COM object using ADSI written in VB6. I have to move this database to a new server. The only real difference between the two...
3
by: Miro | last post by:
First off...thanks in advance for getting me this far. Sorry for all these class posts but im having a heck of a time here trying to get something to work, and have finally got it to work (...
6
by: nild | last post by:
Hello i have a strange problem. I'm using LogonUser to impersonate the user under which my program must run. On Win XP or Server 2003 it works. But on 2000 it doesn't. So i found out, to set...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.