Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2005
    Thanked 0 Times in 0 Posts

    DOM Parser works fine in fire fox not IE

    i am just writing a simple javasript to rotat the text in a div and this works fine in firefox but not ie i get an items.lenght is null or not an object. here is the page

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Documen1</title>
    <script type="text/javascript" >
    var xmlstring = '\
    <rss version="2.0">\
    	  <title>Dr Casalino\'s Testimonial</title>\
    	  <description>"I have been recommending and personally using \
    		DANIEL CHAPTER ONE products for nearly 10 years. \
    		These products are of high quality and effectiveness,\
    		and the DANIEL CHAPTER ONE staff is always helpful\
    		and knowledgeable."\
    	  <title>Cancer - Brain Tumor</title>\
    	  <description>"I had contracted leukemia and had three inoperable tumors. \
    	  	When I decided not to do chemotherapy or radiation, my father sent me \
    		BioMixx and 7 Herb Formula. Each day as I took it and got it into my \
    		system more and more, the better I felt. Then I added Garlic, Siberian \
    		Ginseng, and Bio*Shark."\
    	  <title>Arthritis Story</title>\
    	  <description>"I have rheumatoid arthritis...I felt terrible on the drugs I \
    	  	was given by the doctors. I could hardly walk; I couldn\’t get in or out of \
    		the tub. Now I\’m feeling a lot better; I\’m practically cured! I just have \
    		twinges now and then, but I\’m getting better all the time. BioMixx gave me \
    		energy and helped with the pain. Now I take GS1500, GDU, Micro Cal Plus, \
    		Bio*Shark, and Essential Cell Food as a multivitamin. I\’m doing really well. \
    		I\’d recommend this to anyone."\
    	  <title>Acid Reflux</title>\
    	  <description>Every time I ate, the food felt stuck. Even with water, the food \
    		  didn\’t want to go down. I felt like I was choking. At night I couldn\'t sleep \
    		  due to heartburn. I went to the doctor so I could sleep. He said there was no \
    		  cure, nothing I could do but take medication, or have an operation where they \
    		  wrap the stomach around the esophagus. He said that works in 85% of cases. \
    		  I didn\'t want to take the acid-blocking drug; I thought, if you block digestive \
    		  acid, how can you then digest food?\
    	  <description>Bernon had diabetes for 15 years. He would take Insulin 730-20 \
    		  units in the morning, and R Insulin 2-4 times a day. R Insulin is a fast acting \
    		  insulin to keep the person from going into shock. On Insulin, he felt sluggish. \
    		  Bernon started on Daniel Chapter One products in June 2001. Endo24 - 3 scoops 3 \
    		  times a day at first, now he takes 2 scoops twice a day, CP200 - 2 capsules a \
    		  day; VAN 50 - 2 capsules 3 times day, and Bio C-1000 - 2 capsules twice a day.\
    var xmlobject = new DOMParser().parseFromString(xmlstring, "text/xml");
    var root = xmlobject.getElementsByTagName('rss')[0];
    var tests = root.getElementsByTagName("channel");
    var items = tests[0].getElementsByTagName("item");
    var thisTest = 0;
    function cycleTest()
    			if (++thisTest == items.length)
    				thisTest = 0;
    				var descriptions = items[thisTest].getElementsByTagName("description");
    				var titles = items[thisTest].getElementsByTagName("title");
    				var links = items[thisTest].getElementsByTagName("link");
    				title_val = titles[0].firstChild.nodeValue;
    				descriptions_val = descriptions[0].firstChild.nodeValue;
    				links_val = links[0].firstChild.nodeValue;
    				document.getElementById('test').innerHTML="<span class=\"prodnames_homepage\"><br>"+title_val+"</span><br>\
                            <span class=\"featuredprod_tekst\">"+descriptions_val+"</span><br>\
                            <span class=\"speciallink\"><a href=\""+links_val+"\">read entire testimonial &gt;&gt;</a></span>";
    	// change to next banner every 15 seconds
    	setTimeout("cycleTest()", 15000);
    <!--<script type="text/javascript" src="test_rotate.js"></script>-->
    <body bgcolor=ffffff onload="cycleTest()">
    <div id="test">
    Any Ideas why this doesnt work

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Sydney, Australia
    Thanked 664 Times in 653 Posts
    Try escaping the </ as <\/ so that the browser doesn't think it has reached the end of the script.
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    metro DC
    Thanked 18 Times in 18 Posts
    Umm, I'm fairly sure IE doesn't support DOMParser().

  • #4
    Master Coder
    Join Date
    Feb 2003
    Umeå, Sweden
    Thanked 83 Times in 74 Posts
    Quote Originally Posted by jkd
    Umm, I'm fairly sure IE doesn't support DOMParser().
    Exactly. There are alternatives you can use though. If you have a full document, you can use DOMDocument (with these object members)for instance.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


    Posting Permissions

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