【问题标题】:Accessing a javascript variable in the child html iframe访问子 html iframe 中的 javascript 变量
【发布时间】:2014-02-15 13:05:12
【问题描述】:

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

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

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

【问题讨论】:

    标签: javascript php jquery html iframe


    【解决方案1】:

    iframe 命名,然后:

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

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

    var editorInMainPage = windowObjectInIframe.editor;
    

    【讨论】:

    • windowObjectInIframe.editor 会给你价值
    • @anurupr 非常感谢
    猜你喜欢
    • 1970-01-01
    • 2012-05-24
    • 1970-01-01
    • 2014-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-08
    • 1970-01-01
    相关资源
    最近更新 更多