2

I'm thinking of doing some online file manipulation for mobile users, the idea being that the user provides a URL to the file, then the file contents are modified by the JS, and can then be downloaded. But I haven't been able to figure out how to get the file when it's on a separate domain using just JS.

Is this possible? If so any hints or examples would be appreciated.

Just wanted to add that part of what I wanted to do was make it available without my hosting it. I'm thinking of something like a a file they can host somewhere,and then all of the bandwidth is their own...and that of wherever they are getting the file from of course.

3
  • Same Origin Policy. Commented Dec 12, 2011 at 4:20
  • What is your target browser support and do you have access to the other domain's code?
    – alex
    Commented Dec 12, 2011 at 4:23
  • Main target is Safari under iOS, and no, no access to other domain. The file that I would be getting would always be some kind of binary, never a web page (but not necessarily of any particular mime type).
    – jmoreno
    Commented Dec 12, 2011 at 4:35

2 Answers 2

2

The only way to load contents of a file on another domain is from within a <script> tag. This is how JSONP works. Look into getting your target file into this format.

The other way would be to use a local proxy. Create a web service method that loads and returns the contents of the file, then call that locally using your favorite JavaScript framework.

2
1

Depending on how you think of public webservices, and within some limitations I'm still mapping, you can do this using an ajax call to YQL, like so.

(will expand the answer later).

http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20data.uri%20where%20url=%22http://t3.gstatic.com/images?q=tbn:ANd9GcSyART8OudfFJQ5oBplmhZ6HIIlougzPgwQ9qcgknK8_tivdW0EOg%22

One of the limitations of this method is file size, it currently tops out at 25k.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.