如何在父页面的iframe中调用函数? [英] How to call a function in an iframe from the parent page?
本文介绍了如何在父页面的iframe中调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在父页面的iframe中调用函数?
How to call a function in an iframe from the parent page?
推荐答案
只要框架页位于同一域(或子域,并且您正在设置document.domain)上,就需要访问frame元素的 contentWindow 属性.例如:
As long as the framed page is on the same domain (or on a sub-domain, and you're setting document.domain), you need to access the contentWindow property of the frame element. For example:
$("#myFrame")[0].contentWindow.myFunction();
// or, if jQuery hasn't made you lazy
document.getElementById("myFrame").contentWindow.myFunction();
大多数浏览器还支持 contentDocument ,但Internet Explorer不支持.如果您的框架页面位于其他域中,则会出现访问被拒绝"错误.
Most browsers also support contentDocument, but Internet Explorer doesn't. If your framed page is on a different domain then you'll get an Access Denied error.
这篇关于如何在父页面的iframe中调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文