JavaScript only RSS parser?
-
I wasted a lot of time the other day trying to reinvent the wheel. I wanted to write a web-based RSS parser. I was trying to write it as a JavaScript-only parser. I ran into a lot of frustrations with the security restrictions built into client-side JavaScript, so I thought I'd ask: Can one open and parse a remote file with DOM navigation using only JavaScript, or am I barking up the wrong tree? Thanks!
-
Answer:
I don't believe there's any way to do this with the normal security settings. If you find a way, please let me know.
jpburns at Ask.Metafilter.Com Visit the source
Other answers
i don't know what the restrictions are on javascript, but would the following be possible (i don't think it's a good solution, but it's just an "in principle" argument): - the page is divided into two frames - javascript makes the browser open the rss feed into the "other" frame - browser loads rss file to frame - javascript parses dom in the "other" frame - javascript prints output to "own" frame - repeat (i'm assuming that javascript itself can't load files from hosts other than the source host, but that it can request that the browser do so).
andrew cooke
Nope; javascript can't in any way access a frame that was loaded from a different domain. Deliberate security measure built into the browser. (And a good thing, too, inconvenient though it may be when you're working for a client whose application is spread across three different domains...)
ook
You could use XMLHttpRequest/ActiveXObject("Microsoft.XMLHTTP"), but in Firefox you can only request files from the same host as the JavaScript is being served from (though I'm not sure exactly how this would work with a local file not being served from anywhere). It would work in IE, though. Andrew Cooke's idea is a good one as well. You could use a hidden IFRAME which would be transparent to the user, also. http://developer.apple.com/internet/webcontent/iframe.html would seem to indicate that it's possible to do what you're trying to without too much pain.
IshmaelGraves
javascript parses dom in the "other" frame This is where you'll run into problems. While Javascript can "tell" a frame or iframe to load content from another site, it can't parse information about the HTML page in the other frame. The only way one frame (or window, for that matter) would be allowed access to another frame's DOM would be if both pages resided on the same server.
alan
ok, so is the following a bug i should report? i was playing with svg, which has embedded javascript. the javascript was registered with the dom "onload" event and was being called for any page loaded in the browser (not just the page with the svg graphics). i had to add code that tested for the right page. (this was a beta version of firefox with svg support, so it may well have bugs).
andrew cooke
Andrew: - the page is divided into two frames - javascript makes the browser open the rss feed into the "other" frame - browser loads rss file to frame - javascript parses dom in the "other" frame - javascript prints output to "own" frame - repeat That was the logic I was following, but ran into permissions problems, thus my question. I think that the answer is you can't, but would love to be proven wrong...
jpburns
yeah, sorry. that's how it is with java applets (or used to be, at least, back in the day). i still don't understand why my onload function was called for other pages though. perhaps it's different if the javascript is loaded locally? you can always put a proxy on you server and make a request something like http://you.server.com/proxy?target=other.server.com/path/page.html (but of course that doesn't scale)
andrew cooke
If both domains are controlled by your client/employer/whatever, can you get them to use a hostname? e.g. You want the javascript on www.firstdomain.com to access www.seconddomain.com, so you make bob.firstdomain.com an alias for www.seconddomain.com (This is just off the top of my head so you might want to research/test that this would actually work before trying to implement it)
winston
Related Q & A:
- How To Load Rss Into Php?Best solution by Stack Overflow
- How To Get Full Text From RSS?Best solution by Stack Overflow
- Why is Javascript called Javascript, if it has nothing to do with Java?Best solution by Stack Overflow
- How can I fix parser Error in ASP.NET?Best solution by parse.com
- Wat is RSS n RSS FEED?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.