Let's say I have a button right next to an Iframe and in that Iframe is a download link. Is it possible that when I click the outside button, the download link on the iframe will be clicked?
http://jsfiddle.net/idude/9RQ3N/
<button type="button">Click Me!</button>
<iframe src="http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_a_download" height="400" width="800">
For example, in the jsfiddle link above, how could I make it so that the w3 picture would be downloaded by just clicking the button?
Thanks in advance!
Mozilla's JSChannel is designed for communicating to/fro an iframe using POST. You should consider checking it out.
An example communiqué
The parent HTML could be
Now for the child:
This, when run, will produce and alert saying you said "I'm Bob!"
Obviously, you can do a lot with this. Have fun :)
To access the iFrame DOM, all you need to do is :
or you can get that iFrame by using
or something like that if you prefer not to use an ID for iFrame.
and then you can search for something in that document and trigger a click event on that element.
As correctly pointed by @ssergei, this is not possible for security reasons. This is the jsFiddle I used for catching the errors: http://jsfiddle.net/9RQ3N/5/.
This is the
SecurityError
message that Google Chrome throws:From Firefox:
And from Safari:
Try (this pattern)
jsfiddle http://jsfiddle.net/guest271314/2x4xz/