This page works in IE, but not in Mozilla or Netscape. Could anyone help me figure out why? Am I using unsupported javascript?
-If possible, please suggest an alternate solution.
<html>
<head>
<title>Sample Product Gallery</title>
<script language="JavaScript" type="text/JavaScript">
<!--
//Load the XML to buffer
var xmldoc
function loadXML()
{
//load xml file
// code for IE
if (window.ActiveXObject)
{
xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.async=false;
xmldoc.load("2006_Print_List.xml");
xmldoc.setProperty("SelectionLanguage", "XPath");
}
// code for Mozilla, etc.
else if (document.implementation &&
document.implementation.createDocument)
{
xmldoc=document.implementation.createDocument("","doc",null);
xmldoc.load("2006_Print_List.xml");
}
else
{
alert('Your browser cannot handle this script');
}
}
function buildXMLTable() {
var PrintNode = xmldoc.getElementsByTagName("Print");
var allImgFilenames=new Array();
for (var i=0;i<PrintNode.length;i++) {
allImgFilenames.push (PrintNode.getElementsByTagName("file")[0].getAttribute("href"));
}
var mybody = document.getElementsByTagName("body")[0];
var mytable = document.createElement("table");
mytable.setAttribute("border", "0");
var mytablebody = document.createElement("tbody");
var mycurrent_row, mycurrent_cell, imgTag;
var x = 0, y, len = allImgFilenames.length;
while(x<len) {
mycurrent_row = document.createElement("tr");
for(y=0; y<5; ++y) {
mycurrent_cell = document.createElement("td");
if(x<len) {
imgTag = document.createElement("img");
imgTag.src = "images/" + allImgFilenames[x++];
mycurrent_cell.appendChild(imgTag);
} else {
mycurrent_cell.appendChild(document.createTextNode(" "));
}
mycurrent_row.appendChild(mycurrent_cell);
}
mytablebody.appendChild(mycurrent_row);
}
mytable.appendChild(mytablebody);
mybody.appendChild(mytable);
}
//-->
</script>
</head>
<body onload="loadXML();buildXMLTable()">
</body>
</html>
-If possible, please suggest an alternate solution.
<html>
<head>
<title>Sample Product Gallery</title>
<script language="JavaScript" type="text/JavaScript">
<!--
//Load the XML to buffer
var xmldoc
function loadXML()
{
//load xml file
// code for IE
if (window.ActiveXObject)
{
xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.async=false;
xmldoc.load("2006_Print_List.xml");
xmldoc.setProperty("SelectionLanguage", "XPath");
}
// code for Mozilla, etc.
else if (document.implementation &&
document.implementation.createDocument)
{
xmldoc=document.implementation.createDocument("","doc",null);
xmldoc.load("2006_Print_List.xml");
}
else
{
alert('Your browser cannot handle this script');
}
}
function buildXMLTable() {
var PrintNode = xmldoc.getElementsByTagName("Print");
var allImgFilenames=new Array();
for (var i=0;i<PrintNode.length;i++) {
allImgFilenames.push (PrintNode.getElementsByTagName("file")[0].getAttribute("href"));
}
var mybody = document.getElementsByTagName("body")[0];
var mytable = document.createElement("table");
mytable.setAttribute("border", "0");
var mytablebody = document.createElement("tbody");
var mycurrent_row, mycurrent_cell, imgTag;
var x = 0, y, len = allImgFilenames.length;
while(x<len) {
mycurrent_row = document.createElement("tr");
for(y=0; y<5; ++y) {
mycurrent_cell = document.createElement("td");
if(x<len) {
imgTag = document.createElement("img");
imgTag.src = "images/" + allImgFilenames[x++];
mycurrent_cell.appendChild(imgTag);
} else {
mycurrent_cell.appendChild(document.createTextNode(" "));
}
mycurrent_row.appendChild(mycurrent_cell);
}
mytablebody.appendChild(mycurrent_row);
}
mytable.appendChild(mytablebody);
mybody.appendChild(mytable);
}
//-->
</script>
</head>
<body onload="loadXML();buildXMLTable()">
</body>
</html>