访问子html iframe中的javascript变量

时间:2014-02-15 13:05:13

标签: javascript php jquery html iframe

我的父文档index.php<iframe src="editor.html" width="400" height="300"></iframe>现在文件editor.html包含我想在父窗口中访问的javascript变量editor。我试图使用所谓的“会话变量”,它使用文档窗口,但无法访问它。

我必须有两个这样的文件的原因是,代码编辑器填充文档。所以我必须将它放在一个单独的页面中。

如何从父文档访问子框架中的此变量?感谢

1 个答案:

答案 0 :(得分:1)

iframe命名,然后:

var windowObjectInIframe = window.frames['frame_name'];

如果editor是iframe中的全局变量,您可以像这样访问它:

var editorInMainPage = windowObjectInIframe.editor;