Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can scripts in iframe interact with scripts in the main page

I have an editor with an SWF multi-image uploader. Since not everyone will need to upload pictures in their article, i need to dynamically load this image uploader when necessary. I have to load it in an iframe because the uploader needs some external scripts to be loaded ahead. And since i need it's callback variable for my editor to use I want to know whether scripts in iframe can interacts with scripts in the main page. Or if i can't do that, what's the alternative way to do this?

like image 783
dotslashlu Avatar asked Sep 21 '11 15:09

dotslashlu


1 Answers

If they are on the same domain, yes.

The parent object is the parent window of the iframe.

If you had a variable a in the global scope of the parent window, you could manipulate it in the iframe like this:

parent.a = "new value";

Similarly, if a is a function in the global scope of the parent window, you could call it like this:

parent.a(args);
like image 66
Peter Olson Avatar answered Sep 30 '22 04:09

Peter Olson