从iframe内部调用父Javascript函数 [英] Call parent Javascript function from inside an iframe

查看:81
本文介绍了从iframe内部调用父Javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iframe(在我的域中),iframe有一个文件 iframe.js

I have a iframe (in my domain), that iframe has a file iframe.js.

我的父文档有一个文件 parent.js

My parent document has a file parent.js.

我需要调用<$ c中的函数$ c> parent.js ,来自 iframe.js 中的函数。

I need to call a function that is in parent.js, from a function that is in iframe.js.

我试过做 window.parent.myfunction()这个函数在父级.js file。

I tried doing window.parent.myfunction() this function is in the parent.js file.

但是,它不起作用。只有当我把这个函数放在父页面上时(我的意思是在HTML中),它才有效。

But, it didn't work. Only when I put the function on the parent page (I mean in the HTML), then it worked.

知道如何让它发挥作用吗?

Any idea how to get this to work?

推荐答案

尝试只需 parent.myfunction()。还要100%确定parent.js包含在父文档中。

Try just parent.myfunction(). Also be 100% sure that the parent.js is included in your parent document.

这篇关于从iframe内部调用父Javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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