lanejr
lanejr

Reputation: 13

How can I capture a file downloaded in an iframe?

I have an external site in an iframe with a save button. When the user clicks the save button a json file is downloaded, I would like to be able to capture the contents of this file in my own code. Is there any way to do this?

I read that you cannot specify a download location outside of the browser defined location, and could only find questions related to initiating a download with an iframe rather than capturing one.

Upvotes: 1

Views: 1091

Answers (1)

Zay Lau
Zay Lau

Reputation: 1864

You cannot do it unless you can setup the Access-Control-Allow-Origin (in HttpHeader) of your external site. (check out Access-Control-Allow-Origin on google)

There is a security reason to prevent user read data from other site without permission, for example, the user may logged in the bank site while browsing another site abc.com (in other tab), the bank will not allow abc.com download the users information from them by JavaScript.

  • If your project contains a server side, you could retrieve such data at server side and print out to client side.

Upvotes: 1

Related Questions