在子 iframe 节点中调用 Javascript 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6141784/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Calling Javascript function in child iframe node
提问by Rizwan
How can I call a javaScript function present in a child <iframe>
node from the parent? I am using jquery selector to select the correct iframe node but do not know how to call the function. Also the desired iframe has been added dynamically using jquery.
如何<iframe>
从父节点调用子节点中存在的 javaScript 函数?我正在使用 jquery 选择器来选择正确的 iframe 节点,但不知道如何调用该函数。还使用 jquery 动态添加了所需的 iframe。
For example, the iframe is
例如,iframe 是
<iframe id="frameOne" src="http://form_one.html"><iframe>
I need to do something like this
我需要做这样的事情
$(#frameOne).submitList();
where submitList()
is a function in form_one.html.
其中submitList()
是在form_one.html的函数。
Thanks.
谢谢。
回答by ChristianB
document.getElementById('frameOne').contentWindow.submitList();
frameOne should be the ID of the frame!
frameOne 应该是框架的 ID!
回答by Naftali aka Neal
As long as both of the URLs are in the same domain it should work.
只要两个 URL 在同一个域中,它就应该可以工作。
If they are not, then you run into cross-domain issues
如果不是,那么您会遇到跨域问题