www.webdeveloper.com
Results 1 to 3 of 3

Thread: This code wont work on firefox and crome

  1. #1
    Join Date
    May 2011
    Posts
    4

    This code wont work on firefox and crome

    Hi the code below will not execute properly on chrome or firefox,

    I am using PHPstorm to debug and the watches say that arrays dont get assigned to using the = operartor, I would go as far and say that assigning variables with values from the xmlDoc object dont seem to work
    an example is:

    lenght = xmlDoc.getElementsByTagName('name').length;

    your help would be most appreciated Thanks!.
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript" >
     
    
    
      function parsexml(sender)
      {
    
    var index;
    var fname;
    var lenght;
    var parmsarray = new Array();
    var position
    var aElements = sender.parentNode.parentNode.getElementsByTagName("a");
    var aElementsLength = aElements.length;
    var tmp;
          
    
    
          var success;
    
    	if (document.implementation && document.implementation.createDocument)
    	{
    		xmlDoc = document.implementation.createDocument("", 'doc', null);
    	}
    	else if (window.ActiveXObject)
    	{
    		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    		//alert('internet explorer');
     	}
    	else
    	{
    		alert('Your browser can\'t handle this script');
    		return;
    	}
    
    xmlDoc.async="false";
    success=xmlDoc.load("ClickSlector.xml");
    
    
    for (var i = 0; i < aElementsLength; i++)
    {
        if (aElements[i] == sender)
        {
             position = i;
          //  return pos;
        }
    }
    
    lenght = xmlDoc.getElementsByTagName('name').length;
    
    for(i=0;i<lenght;i++)
    {
    	parmsarray[i]= xmlDoc.getElementsByTagName('name')[i].childNodes[0].nodeValue;
    }
    
          
    tmp =  parmsarray[position];
    
     document.getElementById("header-3").style.backgroundImage = "url("+tmp+")";
    
          str =  document.getElementById("header-3").style.backgroundImage
    }
    
      </script>
    
        <style type="text/css">
    #header-3 {
    	height: 400px;
    	width: 700px;
    }
    </style>
    
    
    
    </head>
    
    <body>
    <div id ="header-3">
    </div>
    
    <ul>
                <li><a href="#" onclick="parsexml(this)">One</a></li>
                <li><a href="#" onclick="parsexml(this)">Two</a></li>
                <li><a href="#" onclick="parsexml(this)">Three</a></li>
                <li><a href="#" onclick="parsexml(this)">Four</a></li>
            </ul>
    
    
    </body>
    </html>
    Last edited by Kor; 05-05-2011 at 02:58 AM. Reason: wrap the code [code][/code]

  2. #2
    Join Date
    May 2011
    Posts
    4
    I'm not sure if i am creating the XML object the correct way for chrome and firefox

  3. #3
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    I guess it should be:
    Code:
    xmlDoc.document.getElementsByTagName('name')[i]
    or even better
    Code:
    xmlDoc.documentElement.getElementsByTagName('name')[i]

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles