从iframe外部调用iframe内的函数 [英] Calling a function inside an iframe from outside the iframe

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

问题描述

我有一个包含iframe的页面。在iframe中我有这样的javascript函数:

I have a page with an iframe. Inside that iframe I have a javascript function like this:

function putme() {}

如何在主页面上调用此函数?

How can I call this function on the main page?

推荐答案

window.frames['frameName'].putme();

请注意,这通常仅在iframe指向同一域上的页面时才有效。出于安全原因,浏览器限制对属于不同域的帧内的页面的访问。

Do note that this usually only works if the iframe is referring to a page on the same domain. Browsers restrict access to pages within frames that belong to a different domain for security reasons.

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

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