Trouble Importing XML in Firefox

Discussion in 'JavaScript' started by radicaldr, Mar 15, 2007.

  1. #1
    I have a very simple page, just testing to see if I'm loading an xml file correctly. the code is as below.

    It works fine in IE, but in Firefox it seems to redirect to a new page just containing the document.write('hi'), and then it's constantly loading.

    What could be wrong?

    EDIT: just realized that it's not displaying perfectly in IE - it doesn't display the "blah blah blah" that I have in the body.

    EDIT EDIT: looks like it's redirecting to a page that simply has the document.write in it.

    <html>
    <head>
    <script language="javascript" type="text/javascript">
    var xmlDoc;
    
    function importXML()
    {
    	if (document.implementation && document.implementation.createDocument)
    	{
    		xmlDoc = document.implementation.createDocument("", "", null);
    		xmlDoc.onload = readXML;
    	}
    	else if (window.ActiveXObject)
    	{
    		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    		xmlDoc.onreadystatechange = function () {
    			if (xmlDoc.readyState == 4) readXML()
    		};
     	}
    	else
    	{
    		alert('Your browser can\'t handle this script');
    		return;
    	}
    	xmlDoc.load("xml_file.xml");
    }
    
    function readXML()
    {
    document.write('hi');
    }
    
    </script>
    </head>
    <body>
    blah
    blah
    blah
    <script language="javascript" type="text/javascript">
    importXML();
    </script>
    
    </body>
    </html>
    Code (markup):
     
    radicaldr, Mar 15, 2007 IP