iframe中的脚本可以与主页中的脚本进行交互吗? [英] Can scripts in iframe interact with scripts in the main page

查看:62
本文介绍了iframe中的脚本可以与主页中的脚本进行交互吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有SWF多图像上传器的编辑器.由于并非所有人都需要在其文章中上传图片,因此我需要在必要时动态加载此图片上传器.我必须将其加载到iframe中,因为上传器需要提前加载一些外部脚本.而且由于需要编辑器使用的回调变量,因此我想知道iframe中的脚本是否可以与主页中的脚本进行交互.还是如果我不能做到这一点,那还有什么替代方法呢?

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?

推荐答案

如果它们在同一个域中,则是.

If they are on the same domain, yes.

parent对象是iframe的父窗口.

The parent object is the parent window of the iframe.

如果在父窗口的全局范围内有一个变量a,则可以像这样在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";

类似地,如果a是父窗口的全局范围内的函数,则可以这样称呼它:

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

parent.a(args);

这篇关于iframe中的脚本可以与主页中的脚本进行交互吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆