javascript读取RSS数据 javascript读取RSS数据
新闻中心(摘自新浪网)
|
News Loading... |
<script> <BR> //Container for ticker. Modify its STYLE attribute to customize style: <BR> var tickercontainer='' <BR> var xmlsource="http://rss.mydrivers.com/Fitting_News.xml"; <BR> var root; <BR> var title; <BR> var link; <BR> var items; <BR> var item; <BR> var images; <BR> var image; <BR> var description; <BR> if (window.ActiveXObject) <BR> { <BR> //document.write("Microsoft.XMLDOM"); <BR> var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); <BR> } <BR> else if (document.implementation && document.implementation.createDocument) <BR> { <BR> //document.write("document.implementation.createDocument"); <BR> var xmlDoc= document.implementation.createDocument("","doc",null); <BR> } <BR> if (typeof xmlDoc!="undefined") <BR> { <BR> //document.write(tickercontainer) <BR> xmlDoc.load(xmlsource) <BR> } <BR> function fetchxml() <BR> { <BR> if (xmlDoc.readyState==4) <BR> output() <BR> else <BR> setTimeout("fetchxml()",10) <BR> } <BR> function output() <BR> { <BR> var temp=""; <BR> root = xmlDoc.getElementsByTagName("channel")[0]; <BR> title =root.getElementsByTagName("title")[0]; <BR> //temp = title.firstChild.nodeValue +"<br>"; <BR> items=root.getElementsByTagName("item"); <BR> for(i=0;i<=items.length-1;i++) <BR> { <BR> item=items[i]; <BR> title=item.getElementsByTagName("title")[0]; <BR> link=item.getElementsByTagName("link")[0]; <BR> description=item.getElementsByTagName("description")[0]; <BR> temp = temp + "<font size=-1><a href=" + link.firstChild.nodeValue+ " target='_bank'>" + title.firstChild.nodeValue +"<br><br>"; <BR> //temp = temp +"<font size=-1>" + description.firstChild.nodeValue + "<br><br>"; <BR> document.getElementById("container").innerHTML = temp; <BR> } <BR> } <BR> if (window.ActiveXObject) <BR> fetchxml() <BR> else if (typeof xmlDoc!="undefined") <BR> xmlDoc.onload=output <BR> </script>