从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
.
我需要调用 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.