Jump to content

Javascript Not Working In Ie


dmorgado.design@gmail.com
 Share

Recommended Posts

Hi! I'm trying to build my first website. However, I'm having problems with Javascript in IE.The website is an online portfolio. I'm using Javascript to parse a XML file, and use it for content for a lightbox script. so for each gallery I'm calling 2 scripts: Lightbox, and my own script which parses the XML and writes the results in the page. both scripts are on an external document. In firefox it works just fine, however in IE it doesn't.The code, in the HTML page:

<head><script type="text/javascript" src="lightbox.js"></script></head><body><script type="text/javascript" src="2dsamples.js"></script></body>

My javascript code, for the XML parsing

var xmlDoc=null;if (window.ActiveXObject){// code for IExmlDoc=new ActiveXObject("Microsoft.XMLDOM");}else if (document.implementation.createDocument){// code for Mozilla, Firefox, Opera, etc.xmlDoc=document.implementation.createDocument("","",null);}else{alert('Your browser cannot handle this script');}if (xmlDoc!=null){ xmlDoc.async=false;xmlDoc.load("databases/2dsamples.xml");var x=xmlDoc.getElementsByTagName("picture");for (i=0;i<x.length;i++){var IMAGE= x[i].getElementsByTagName("link")[0].childNodes[0].nodeValuevar NAME=  x[i].getElementsByTagName("picname")[0].childNodes[0].nodeValuevar DESCRIPTION= x[i].getElementsByTagName("description")[0].childNodes[0].nodeValuevar THUMB= "<img src='" + x[i].getElementsByTagName("thumb")[0].childNodes[0].nodeValue + "' width=\"100px\" height=\"100px\"/>"var TITLE= "title='" + x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue + "'>"document.write("<a href='" + IMAGE + "' rel=\"lightbox\"");document.write(TITLE)document.write(THUMB);document.write("</a>");document.write("   ")}}

And then of course there's also the standard Lightbox script, which I don't know if I should post here.Any help on this matter would be apreciated.Thanks in advance :)

Link to comment
Share on other sites

Since this appears to only run when the page is loaded, I recommend using a server-side language for it instead. This is for two reasons: Search engine robots can see the content, and people can see the content no matter what browser or settings they are using.In PHP there's the DOMDocument class to read XML files.

Link to comment
Share on other sites

You're declaring variables inside a loop. It's illegal to declare the same variable twice, which is what the loop is doing. Try this instead:

var IMAGE,NAME,DESCRIPTION,THUMB,TITLE;for (i=0;i<x.length;i++) {  IMAGE = x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue;  NAME =  x[i].getElementsByTagName("picname")[0].childNodes[0].nodeValue;  DESCRIPTION = x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue;  THUMB = "<img src='" + x[i].getElementsByTagName("thumb")[0].childNodes[0].nodeValue + "' width=\"100px\" height=\"100px\"/>";  TITLE = "title='" + x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue + "'>"  document.write("<a href='" + IMAGE + "' rel=\"lightbox\"");  document.write(TITLE);  document.write(THUMB);  document.write("</a> ");}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...