Re: How to load a webpage !!
- From: Bart Van der Donck <bart@xxxxxxxxxx>
- Date: Thu, 3 Apr 2008 05:31:41 -0700 (PDT)
"Evertjan." wrote:
karsagar...@xxxxxxxxx wrote:
I have a webpage ex.http://rss.cnn.com/rss/cnn_topstories.rss. I
would like to access the associated XML file (which you get when you
do View -> Page source or Ctrl+U). Is there a way to do this using
javascript.
var http = new XMLHttpRequest(); // IE7 tested
That is not backwards compatible with IE5 and IE6 (still quite widely
used these days).
var http = null;
if (window.XMLHttpRequest) {
http = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
http = new ActiveXObject('Microsoft.XMLHTTP');
}
function getUrl(url) {
http.open("GET",url,false);
http.send();
if (http.readyState == 4) {
if (http.status == 200) {
return http.responseText;
};
};
};
var s = getUrl('http://rss.cnn.com/rss/cnn_topstories.rss');
s = s.replace(/</g,'<br><');
document.write(s);
Microsoft Internet Explorer has the ugly habit to allow remote
XMLHttpRequest calls from the local filesystem; that's why this code
*appears* to work fine, while in reality - executed from a web server
- it doesn't.
The original poster might be interested in a cross-domain AJAX program
like e.g.
http://www.ajax-cross-domain.com
There are other possibilities, which basically make a web server/proxy
think that various resources belong to a same domain.
Cheers,
--
Bart
.
- Follow-Ups:
- Re: How to load a webpage !!
- From: Evertjan.
- Re: How to load a webpage !!
- References:
- Re: How to load a webpage !!
- From: karsagarwal@xxxxxxxxx
- Re: How to load a webpage !!
- From: Evertjan.
- Re: How to load a webpage !!
- Prev by Date: Re: Is it about providing -this- value?
- Next by Date: Re: alter the download settings of mozilla firefox browser using javascript
- Previous by thread: Re: How to load a webpage !!
- Next by thread: Re: How to load a webpage !!
- Index(es):
Relevant Pages
|