views:

1139

answers:

4

Can JavaScript load an RSS XML feed from Yahoo?

Is client-side JS allowed to access 3rd-party domains?

A: 

I'm not sure about JS but I know that you can use one of google's APIs and they have an RSS reader. I know this probably isn't what you want, but if you read through the documentation you may be able to get your answer on how it works.

Lucas McCoy
A: 

An easy way to do this is to proxy the request through the server that your page resides on. Steps are:

  1. Write a server side script performs an http request on the rss feed, when that script itself is request (i.e. via get or post)
  2. Use ajax to request the server side script, or just call it from the main script for that page.
  3. The server side script then returns the feed source in some displayable form.
  4. Profit!

On IE 8 and FF 3.1(not certain), it is possible to make these requests through specialized cross site calls, but the last generation of browsers will still cause problems. See:

http://dannythorpe.com/2009/01/15/ie8-cross-domain-request-support-demo/ http://ejohn.org/blog/cross-site-xmlhttprequest/ Feature is restricted in FF 3.0, unclear if it will be back in 3.1

However, the steps above are guaranteed not to run afoul of any browser CSS security, at the expense of some lag and extra hw load on your server.

Dana the Sane
A: 

Not directly. You can use Dana's suggestion of proxing the request, or look into a method called JSONP, which essentially wraps the returned JSON object in a custom callback function, requested by a script tag you inject into your DOM. Most API providers support this (including Yahoo's APIs).

bck
+1  A: 
swirleydude
Damn good idea. Its somewhat like having a proxy on my own server though!
Jenko
It's better than having your own proxy because you can filter the data on Yahoo's server before it's even sent to you, it would take alot of effort to do that with a personal proxy.
swirleydude