开发者

Calling iframe function

开发者 https://www.devze.com 2022-12-14 21:37 出处:网络
Is there a way to call a JavaScript function that is inside an IFrame from the开发者_运维问答 parent? That depends on the contents of the IFrame. If the content is from another domain then you\'re out

Is there a way to call a JavaScript function that is inside an IFrame from the开发者_运维问答 parent?


That depends on the contents of the IFrame. If the content is from another domain then you're out of luck, as most modern browsers have closed that loophole for cross-site attacks.

However, if the content is from the SAME domain then you can use it as it were simply another method on the IFrame window object. If I recall correctly you can use something like window.frames["_your_IFrame_ID_"].window.functionOrMethodName().


Where are you wanting the function to be called against? Moreover, what are you wanting it to do?

When you call it are you wanting it to 1) Operate on items in the container page? 2) Operate on items in the IFrame itself 3) Be a generic function accessible by both container and frame.

As far as I am aware

1) Isn't possible

2) Might be possible, given Paulo Santos' answer.

3) Should put function in a common file.


As far as I know is this rather complicated. You can set up a Cross Domain Communication Channel. For Facebook applications this kind of thing is quite common. This, of course, only works if both sites play along.

0

精彩评论

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

关注公众号