使用Javascript从iframe获取对象 [英] get object from iframe with Javascript
本文介绍了使用Javascript从iframe获取对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我的页面上有一个iframe.现在我想从iframe中获取对象或在父对象中调用Java函数.
我能怎么做?
Hi all
I have an iframe in my page. now i want get an object or call a java function in parent from iframe.
how can i do? is possible?!
推荐答案
如果我正确理解了您的问题,您想从同一页面的IFrame调用父页面方法.YES you can
.
假设您具有以下结构
If I understood your question correctly, you want to call a Parent Page method from IFrame in the same page.YES you can
.
Let say you have below Structure
[mainpage markup]
[main page JS ]
function TestMethod()
{
}
[main page JS ]
[iframe id="myiframe"]
[/iframe]
[mainpage markup]
然后您可以按以下方式调用TestMethod
Then you can call the TestMethod
as below
document.getElementById(''myiframe'').contentWindow.TestMethod();
contentWindow将返回您的父容器.希望这对您有帮助!
contentWindow will return you parent container. Hope this helps !!
这篇关于使用Javascript从iframe获取对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文