下载ajaxRss阅读器源码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!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 runat="server">
    
<title>JavaScript RSS 阅读器</title>
    
<meta http-equiv="Content-Type" content="text/html"; charset="gb2312" />
    
<style type="text/css">
        body
{font-family:verdana,arial,helvetica,sans-serif;font-size:10pt;}
        a
{color:#003399;}
        a:hover
{color:#ff9900;}
        #feedOutput
{border-style:solid;border-width:1px;width:50%;background-color:#fafad2;padding:1em;}
    
</style>
    
<script type="text/javascript">
        
function readRSS(feedURL){
            
var request;
            
try{
            
/* 创建XMLHttpRequest对象 */
                request 
= new XMLHttpRequest();
            }
catch(e){request = new ActiveXObject("Msxml2.XMLHTTP");}
            
try{
            
/* 如果本地文件要访问http URL */
                netscape.security.PrivilegeManager.enablePrivilege(
"UniversalBrowserRead");
            }
catch(e){}
            request.open(
"GET",feedURL,false);
            request.send(
null);
            
var feed=request.responseXML;
            
var itemList = feed.getElementsByTagName('item');
            
var numItems=itemList.length;
            
/* 为项目列表创建html */
            
var newULTag=document.createElement('ul');
            
for(var i=0;i<numItems;i++){
                
/* 创建一个新的项目列表 */
                
var newLITag=document.createElement('li');
                
/* 得到项目标题及其文本 */
                
var itemTitle = itemList[i].getElementsByTagName('title');
                
var newItemTitleTxt=document.createTextNode(itemTitle[0].firstChild.nodeValue);
                
/* 创建一个指向项目的连接 */
                
var itemURL = itemList[i].getElementsByTagName('link');
                
var newATag = document.createElement('a');
                newATag 
= document.createElement('a');
                newATag.href
=itemURL[0].firstChild.nodeValue;
                newATag.appendChild(newItemTitleTxt);
                
/* 获取项目描述 */
                
var itemDescription = itemList[i].getElementsByTagName('description');
                
var descriptionTxt = document.createTextNode(itemDescription[0].firstChild.nodeValue);
                
var newPTag = document.createElement('p');
                newPTag.appendChild(descriptionTxt);
                
/* 创建一个追加html */
                newLITag.appendChild(newATag);
                newLITag.appendChild(newPTag);
                newULTag.appendChild(newLITag);
            }
            document.getElementById(
'feedOutput').appendChild(newULTag);
        }
    
</script>
</head>
<body>
    
<h1 align="center">简单Javascript制作的RSS阅读器</h1>
    
<h2 align="center"><href="http://www.docin.com/p-3620097.html">Ajax.net实现的动态输入项</a></h2>
    
<form name="feedForm" id="feedForm" method="get" action="#" runat="server">
    
<b>RSS Feed URL:</b><input type="text" name="feedURL" value="http://demos.javascriptref.com/newsfeed.xml" size="50" />
    
<input type="button" value="阅读" onclick="readRSS(this.form.feedURL.value);" />
    
<div>
    
    
</div>
    
</form>
    
<div id="feedOutput"><br /></div>
    
<h2>For other feeds try</h2>
    
<ul>
    
<li>http://rss.news.yahoo.com/rss/topstories</li>
    
</ul>
</body>
</html>
posted on 2008-12-15 11:44  阿炳  阅读(890)  评论(2编辑  收藏  举报