
177 - PUT A CALENDAR XML WIDGET IN YOUR BLOG
HaCK
# 70
<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAvAApH2nqapCL4bg4uRTR
VvfzRR1JzaEnpQZ7YiBBUK6oRrqkchPJMd0Nf2npnhREFa8-1ypJu1y-cB4DQ"></script>
Next, still in the head portion of the HTML, there’s an inline JavaScript snippet.
<script type="text/javascript">
google.load("feeds", "1");
function initialize() {
var feed = new google.feeds.Feed("http://www.digg.com/rss/index.xml");
feed.load(function(result) {
if (!result.error) {
var container = document.getElementById("feed");
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var div = document.createElement("div");
div.appendChild(document.createTextNode(entry.title));
container.appendChild(div);
}
}
});
}
google.setOnLoadCallback(initialize);
</script>
</head>
Finally, the body element of the HTML shows a div (division) element container to hold the output of
the JavaScript:
<body>
<div id="feed"></div>
</body>
</html>
The initialize function of the JavaScript example portion is the most interesting here. It rst
loads an RSS feed from social news web site Digg.com. If the feed loaded correctly, and did not
encounter errors, the container element in the HTML body will be selected. Now, a for loop iterates
through all the different news elements of the Digg feed, highlighted in bold in ...