T
Trevor L.
Following some earleir advice , i set u an RSS feed on my website.
However, it only works inIE6, not Firefox1.5
Placing alerts in the code tells me that the test
"if(window.ActiveXObject)" returns false in Firefox
Questions
1. How do I turn on ActiveX objects in Firefox?
Or if I can't
2 .How can I modify the code to work in Firefox ?
The code follows below.
Another alerts tell me that this code does not execute in Firefox
xmlDoc.load(URI)
==========
<html>
<!-- rss-reader.html -->
<head>
<script type="text/javascript">
//-------------------
function readRSS(URI)
{
//----Internal function --------
function formatRSS()
{
var item = items.getElementsByTagName('item')
var items_count = item.length
var pubDate = new Array(),
date = new Array(),
link = new Array(),
title = new Array(),
description = new Array(),
guid = new Array()
for(var i = 0; i < items_count; i++)
{
if(item.getElementsByTagName('pubDate').length==1)
pubDate=item.getElementsByTagName('pubDate')[0]
if(item.getElementsByTagName('dc:date').length==1)
date = item.getElementsByTagName('dc:date')[0]
if(item.getElementsByTagName('link').length==1)
link = item.getElementsByTagName('link')[0]
if(item.getElementsByTagName('guid').length==1)
guid = item.getElementsByTagName('guid')[0]
if(item.getElementsByTagName('title').length==1)
title = item.getElementsByTagName('title')[0]
if(item.getElementsByTagName('description').length==1)
description = item.getElementsByTagName('description')[0]
}
if((description.length==0) && (title.length==0))
return false
document.write('<html><head><title>' +
xmlDoc.getElementsByTagName('title')[0].firstChild.nodeValue
+ '</title></head><body>')
document.write('<span style="font-family:verdana,arial,helvetica;
font-size:8pt">')
document.write('<center><a href="index_main.html"><h3>[Go
Back]</h3></a></center>')
document.write('<center><a href="' +
xmlDoc.getElementsByTagName('link')[0].firstChild.nodeValue + '"><h2>'
+
xmlDoc.getElementsByTagName('description')[0].firstChild.nodeValue
+ '</h2></a></center>')
var ws = /\S/
for(var i = 0; i < items_count; i++)
{
var pubDate_w, title_w, link_w
pubDate_w = (pubDate.length>0) ? pubDate.firstChild.nodeValue :
"<i>Date NA</i>"
if(document.all)
title_w = (title.length > 0) ? title.text : "<i>Untitled</i>"
else
title_w = (title.length > 0) ? title.firstChild.nodeValue :
"<i>Untitled</i>"
link_w = (link.length > 0) ? link.firstChild.nodeValue : ""
if(link.length == 0)
link_w = (guid.length > 0) ? guid.firstChild.nodeValue : ""
if(title.length > 0)
title_w = (!ws.test(title_w)) ? "<i>Untitled</i>" : title_w
if(pubDate.length == 0)
pubDate_w = (date.length > 0) ? date.firstChild.nodeValue : "<i>Date
NA</i>"
document.write('<a href="' + link_w + '"><b>' + title_w + '</b></a> <b>['
+ pubDate_w + ']</b><br>')
if(description.length > 0)
document.write('<font size="-1">' + description.firstChild.nodeValue
+ '</font><hr noshade><br>')
}
document.write('</span></body></html>')
}
//-------------------------------
if(window.ActiveXObject)
{ alert ('window.ActiveXObject')
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async = false
while(xmlDoc.readyState != 4)
document.write('Loading...')
}
else
{ alert ('Not window.ActiveXObject')
if(document.implementation && document.implementation.createDocument)
xmlDoc = document.implementation.createDocument("","doc",null) }
alert ('xmlDoc.load starting')
xmlDoc.load(URI)
alert ('xmlDoc.load complete')
items = xmlDoc // global - passed to formatRSS
alert ('typeof(xmlDoc) = ' + typeof(xmlDoc))
if(typeof(xmlDoc) != "undefined")
{
if(window.ActiveXObject)
formatRSS()
else
xmlDoc.onload = formatRSS
}
}
//-------------------
function checkString()
{
var loc = document.location.href.split("?")
if(loc.length > 1)
{
URI = loc[1].split("=")
if(URI.length > 1)
{
var retURI=""
for(var i = 1; i < URI.length; i++)
retURI += URI
try {readRSS(unescape(retURI)) }
catch(e) {}
}
}
}
//-------------------
</script>
</head>
<body onload="checkString();">
<table><tr><td>
<h1>JavaScript RSS Reader</h1>
<form id="form1" name="form1" method="get" action="rss-reader.html">
<b>RSS URL: </b>
<input type="text" id="URI" name="URI" value="http://" />
<input type="submit" value="Read RSS" />
</form>
</td></tr></table>
</body>
However, it only works inIE6, not Firefox1.5
Placing alerts in the code tells me that the test
"if(window.ActiveXObject)" returns false in Firefox
Questions
1. How do I turn on ActiveX objects in Firefox?
Or if I can't
2 .How can I modify the code to work in Firefox ?
The code follows below.
Another alerts tell me that this code does not execute in Firefox
xmlDoc.load(URI)
==========
<html>
<!-- rss-reader.html -->
<head>
<script type="text/javascript">
//-------------------
function readRSS(URI)
{
//----Internal function --------
function formatRSS()
{
var item = items.getElementsByTagName('item')
var items_count = item.length
var pubDate = new Array(),
date = new Array(),
link = new Array(),
title = new Array(),
description = new Array(),
guid = new Array()
for(var i = 0; i < items_count; i++)
{
if(item.getElementsByTagName('pubDate').length==1)
pubDate=item.getElementsByTagName('pubDate')[0]
if(item.getElementsByTagName('dc:date').length==1)
date = item.getElementsByTagName('dc:date')[0]
if(item.getElementsByTagName('link').length==1)
link = item.getElementsByTagName('link')[0]
if(item.getElementsByTagName('guid').length==1)
guid = item.getElementsByTagName('guid')[0]
if(item.getElementsByTagName('title').length==1)
title = item.getElementsByTagName('title')[0]
if(item.getElementsByTagName('description').length==1)
description = item.getElementsByTagName('description')[0]
}
if((description.length==0) && (title.length==0))
return false
document.write('<html><head><title>' +
xmlDoc.getElementsByTagName('title')[0].firstChild.nodeValue
+ '</title></head><body>')
document.write('<span style="font-family:verdana,arial,helvetica;
font-size:8pt">')
document.write('<center><a href="index_main.html"><h3>[Go
Back]</h3></a></center>')
document.write('<center><a href="' +
xmlDoc.getElementsByTagName('link')[0].firstChild.nodeValue + '"><h2>'
+
xmlDoc.getElementsByTagName('description')[0].firstChild.nodeValue
+ '</h2></a></center>')
var ws = /\S/
for(var i = 0; i < items_count; i++)
{
var pubDate_w, title_w, link_w
pubDate_w = (pubDate.length>0) ? pubDate.firstChild.nodeValue :
"<i>Date NA</i>"
if(document.all)
title_w = (title.length > 0) ? title.text : "<i>Untitled</i>"
else
title_w = (title.length > 0) ? title.firstChild.nodeValue :
"<i>Untitled</i>"
link_w = (link.length > 0) ? link.firstChild.nodeValue : ""
if(link.length == 0)
link_w = (guid.length > 0) ? guid.firstChild.nodeValue : ""
if(title.length > 0)
title_w = (!ws.test(title_w)) ? "<i>Untitled</i>" : title_w
if(pubDate.length == 0)
pubDate_w = (date.length > 0) ? date.firstChild.nodeValue : "<i>Date
NA</i>"
document.write('<a href="' + link_w + '"><b>' + title_w + '</b></a> <b>['
+ pubDate_w + ']</b><br>')
if(description.length > 0)
document.write('<font size="-1">' + description.firstChild.nodeValue
+ '</font><hr noshade><br>')
}
document.write('</span></body></html>')
}
//-------------------------------
if(window.ActiveXObject)
{ alert ('window.ActiveXObject')
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async = false
while(xmlDoc.readyState != 4)
document.write('Loading...')
}
else
{ alert ('Not window.ActiveXObject')
if(document.implementation && document.implementation.createDocument)
xmlDoc = document.implementation.createDocument("","doc",null) }
alert ('xmlDoc.load starting')
xmlDoc.load(URI)
alert ('xmlDoc.load complete')
items = xmlDoc // global - passed to formatRSS
alert ('typeof(xmlDoc) = ' + typeof(xmlDoc))
if(typeof(xmlDoc) != "undefined")
{
if(window.ActiveXObject)
formatRSS()
else
xmlDoc.onload = formatRSS
}
}
//-------------------
function checkString()
{
var loc = document.location.href.split("?")
if(loc.length > 1)
{
URI = loc[1].split("=")
if(URI.length > 1)
{
var retURI=""
for(var i = 1; i < URI.length; i++)
retURI += URI
try {readRSS(unescape(retURI)) }
catch(e) {}
}
}
}
//-------------------
</script>
</head>
<body onload="checkString();">
<table><tr><td>
<h1>JavaScript RSS Reader</h1>
<form id="form1" name="form1" method="get" action="rss-reader.html">
<b>RSS URL: </b>
<input type="text" id="URI" name="URI" value="http://" />
<input type="submit" value="Read RSS" />
</form>
</td></tr></table>
</body>