5

Can JavaScript load an RSS XML feed from Yahoo?

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

5 Answers 5

2

You can use the technique outlined in my blog post Unwritten guide to Yahoo Query Langauge

You would query the XML data table with a yql statment like this:

select * from xml
  where url="http://path/to/xml
Then you would add a script tag to your html (can be done with document.createElement('script')) with a src http://query.yahooapis.com/v1/public/yql?q={your yql here}&format=json&callback={your function here} where {your yql here} is replace with a URI Encoded version of you yql statment.

Sign up to request clarification or add additional context in comments.

2 Comments

Damn good idea. Its somewhat like having a proxy on my own server though!
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.
2

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.

Comments

2

You can use the Google Feed API to load RSS in JavaScript from any domain / server. More than just a proxy, it actually serves the RSS content from the Google cache instead of hitting the original server. This could be a lifesaver for small servers that can't handle Slashdot traffic surges.

I used the Feed API for a cross-site RSS access in an article on Silverlight several years ago.

Comments

0

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.

Comments

0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.