📄 rss.js
字号:
function createAjaxObj(){
var httprequest=false
if (window.XMLHttpRequest)
{ // if Mozilla, Safari etc
httprequest=new XMLHttpRequest()
if (httprequest.overrideMimeType)
httprequest.overrideMimeType('text/xml')
}
else if (window.ActiveXObject)
{ // if IE
try {
httprequest=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
return httprequest
}
function RSSReader_ajax(RSS_url, cachetime, divId)
{
this.RSS_url=RSS_url;
this.cachetime=cachetime;
this.tickerid=divId;
this.title=[];
this.link=[];
this.desc=[];
this.pubdate=[];
this.ajaxobj=createAjaxObj();
this.getAjaxcontent();
document.getElementById(this.tickerid).innerHTML="Initializing....";
}
RSSReader_ajax.prototype.getAjaxcontent=function()
{
if (this.ajaxobj)
{
var instanceOfTicker=this;
this.ajaxobj.onreadystatechange=function(){instanceOfTicker.initialize();}
var rssURL="http://rss.sina.com.cn/news/allnews/sports.xml";
//alert(rssURL);
//var submitURL="rss?url="+this.RSS_url+"&cache="+this.cachetime;
this.ajaxobj.open('GET', rssURL, true);
this.ajaxobj.send(null);
}
}
RSSReader_ajax.prototype.initialize=function()
{
if (this.ajaxobj.readyState == 4)
{
if (this.ajaxobj.status==200)
{
var xmldata=this.ajaxobj.responseXML;
if(xmldata.getElementsByTagName("item").length==0)
{
document.getElementById(this.tickerid).innerHTML="<b>Error</b> fetching remote RSS feed!<br />"+this.ajaxobj.responseText;
return;
}
var instanceOfTicker=this;
this.feeditems=xmldata.getElementsByTagName("item");
//alert(this.feeditems.length);
for (var i=0; i<this.feeditems.length; i++)
{
this.title[i]=this.feeditems[i].getElementsByTagName("title")[0].firstChild.nodeValue;
this.link[i]=this.feeditems[i].getElementsByTagName("link")[0].firstChild.nodeValue;
//this.desc[i]=this.feeditems[i].getElementsByTagName("desciption")[0].firstChild.nodeValue;
this.pubdate[i]=this.feeditems[i].getElementsByTagName("pubDate")[0].firstChild.nodeValue;
}
//alert(this.title[0]);
this.rotatemsg();
}
}
}
RSSReader_ajax.prototype.rotatemsg=function()
{
var tickerDiv=document.getElementById(this.tickerid);
var tickercontent="";
for( var i=0;i<this.title.length;i++)
{
var linktitle='<div class="rsstitle"><a href="'+this.link[i]+'">'+this.title[i]+'</a></div>';
// var description='<div class="rssdescription">'+this.desc[i]+'</div>';
var feeddate='<div class="rssdate">'+this.pubdate[i]+'</div>';
tickercontent=tickercontent+linktitle+feeddate;
}
tickerDiv.innerHTML=tickercontent;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -