在iframe中运行功能 [英] Run function in iframe
问题描述
嗨
我之前已经做过(也许不是使用iframe,而是使用框架集),所以我知道它可以工作,但是我想做的是在另一个iframe中运行一个函数
例如:
我有一个名为"Main"的iframe,在Main中有一个包含以下内容的页面:
< script>
函数test()
{
alert(有效")
}
</script>
如何从另一个iframe运行测试功能.我试过了:
< a href ="javascript:test();" target ="Main">点击此处进行测试</a>而且没有用
有办法吗?我找不到以前做过的旧文件.
提前非常感谢!
我找到了旧文件,我使用了< a href = javascript:parent.frames [''Main''].test();>点击此处进行测试</a>但是它仅在Internet Explorer中有效.我需要在Chrome中工作,因为我正在基于Chrome构建数据库,其中大多数功能在IE中不起作用
Hi
I have done this before (maybe not with iframes, but with framesets) so I know it works, but what I''m trying to do is run a function in another iframe
eg:
I have an iframe called "Main", and in Main it has a page with the following:
<script>
function test()
{
alert("It works")
}
</script>
How would I run the test function from another iframe. I have tried:
<a href="javascript:test();" target="Main">Click here to test</a> and it didn''t work
Is there a way? I can''t find the old files where I have done this before.
Thanks very much in advance!
I found the old files, I used <a href=javascript:parent.frames[''Main''].test();>Click here to test</a> however it only works in Internet Explorer. I need this to work in Chrome as I am building a database based in the Chrome where most of the functions would not work in IE
推荐答案
您可以使用
Can you use
document.getElementById(''Main'').contentWindow.test();
?
这篇关于在iframe中运行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!