Hello. My instructor, a couple other students, and I can't figure out how to make this not crash in FireFox.
WHAT I WANT TO HAPPEN:
I want to be able to use the getstory function to write to the inner HTML of the div tag with the id of spotlight instead of just writing to the page like it is now.
THE PROBLEM:
When loaded in Internet Explorer it works fine. When loaded in Firefox, it causes it to crash.
HTML FILE:
THE XML FILE:Code:<html> <head> <title></title> </head> <body> <div class='side' id='spotlight'> blah </div> <script type="text/javascript" src="spotlight.js"></script> </body> </html>
THE JS FILE:Code:<?xml version="1.0" encoding="UTF-8" ?> <articles> <article> <title>Spotlight</title> <user>Miyabi</user> <story> FINALLY! I have the spotlight up and running! We should have some news up here soon. :] </story> </article> <article> <title>Golden Sun DS</title> <user>Miyabi</user> <story> I mostly posted this for testing, but OMG they FINALLY announced it! </story> </article> </articles>
Code:var xmlDoc; window.onLoad = loadXML('spotlight.xml'); var spotlight = document.getElementById("spotlight"); alert(document.getElementById("spotlight")); function loadXML(file) { if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load(file); getstrings(); } else if (document.implementation && document.implementation.createDocument) { xmlDoc= document.implementation.createDocument("","",null); xmlDoc.load(file); xmlDoc.onload = getstrings; } else { return; } //end if } //end loadXML function getstrings() { articles = xmlDoc.getElementsByTagName("article"); var title; var author; var story; document.write("<center>"); getRand(); document.write("</center>"); } //end getstrings function getRand(){ var number; var story; number = Math.random(); number *= articles.length; story = Math.round(number/2); getStory(story); } function getStory(i){ title = xmlDoc.getElementsByTagName("title")[i].childNodes[0].nodeValue; document.write("<b><u>" + title + "</b></u>"); document.write("<br />"); author = xmlDoc.getElementsByTagName("user")[i].childNodes[0].nodeValue; document.write("<i>" + author + "</i>"); document.write("<br />"); story = xmlDoc.getElementsByTagName("story")[i].childNodes[0].nodeValue; document.write(story); document.write("<br />"); }


Reply With Quote
Bookmarks