真正的跨浏览器(主要是支持FireFox),远程加载并解析XMl文件。之前在网上看到很多说在FireFox下获取远程XMl文件的方法都无效,主要是因跨域问题。今天特此贴出本人用的一个方法,真正的街解决了问题,觉得好的朋友顶一个!
Code:
/*js psrt*/----file name:"custom.js"
function getRss(){
var url="http://cn.bing.com/news/search?form=QBLH&scope=news&filt=all&format=rss&q=s";
var _item;
var list = "";
var xmlDoc;
xhttp=new window.XMLHttpRequest();
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
xhttp.open("GET",url,true);
xhttp.send(null);
xhttp.onreadystatechange = function()
{
if(xhttp.readyState == 4)
{
if(xhttp.status == 200)
{
xmlDoc=xhttp.responseXML;
items = xmlDoc.getElementsByTagName("item");
for(j = 0;j<items.length;j++)
{
_item = items[j];
title = _item.getElementsByTagName("title")[0];
list += "<p /><a href='#' id='titile_"+j+"' onclick='openDialog("+j+")'>"
+ title.firstChild.nodeValue +"</a></p>";
} //end of for
document.getElementById("show").innerHTML=list;
} //end of if
else{alert("status is " + request.status);}
} //end of if
} //end of function
} // end of getRss()
/*you can test with this html page under FF browser*/
<html>
<head>
<title>test</title>
<script type="text/javascript" src="custom.js"></script>
</head>
<body>
<input type="button" value="Search" class="Button" id="search" onclick="getRss()"/>
<div id="show">the titles:</div>
</body>
</html>