开发者

Trigger a function from an iframe but execute as if triggered from parent document?

开发者 https://www.devze.com 2023-03-28 04:04 出处:网络
I\'ve got a parent page, with a child iframe... When clicking on a specific button inside the child iframe, I want a function to trigger as if it were originating from the parent document itself.

I've got a parent page, with a child iframe... When clicking on a specific button inside the child iframe, I want a function to trigger as if it were originating from the parent document itself.

The function chain I have is rather long, and dependent no a lot of variables and what not. When I trigger the function (by 开发者_运维问答adding onclick to the button in the child frame), the chained functions fail because the variables are not recognized (since they don't exist within the child DOM's scope).

Any thoughtful solutions?


If a function parentFunction() is defined in the parent frame you can call it from the child frame by saying parent.parentFunction(); (and pass it any parameters it needs for values defined in the child).

(By the way, it's probably not a good sign that you have a chain of functions that are all dependent on variables that I assume from your description are globals.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号