javascript 从子框架调用父文件中的函数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3615141/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 01:44:42  来源:igfitidea点击:

Calling a function in parent file from child frame?

javascripthtmlfunction

提问by David

I have a function that resizes the colwidth ratio of my framesetin "frame.html":

我有一个函数可以调整colframeset在“frame.html”中的宽度比例:

<frameset id="set" cols="*,*" FRAMESPACING=0 BORDER=3 BORDERCOLOR=#eeeeee>
    <frame src="index.html">
    <frame src="index2.html"> 
    <noframes></noframes> 
</frameset> 

The function works fine when called from "frame.html", However i want to call said function from the child file "index.html"... the function needs to remain in the parent file in order to run properly... How can I call my function in frame.htmlfrom index.html

从“frame.html”调用时该函数工作正常,但是我想从子文件“index.html”调用所述函数......该函数需要保留在父文件中才能正常运行......如何我可以调用我的函数frame.htmlindex.html

回答by Karl Johan

Just try parent.functionName()it should work.

试一试parent.functionName()应该可以的。

Edit

编辑



Just to be sure that the scope is correct you should probably call window.parent.functionName()instead to be sure that it is actually the frames parent that is referenced

只是为了确保范围是正确的,您可能应该调用window.parent.functionName()以确保它实际上是引用的框架父级

Edit 2

编辑 2



Check out this answerit seems to handle the same chrome issue.

查看这个答案,它似乎处理了相同的 chrome 问题。

Hope it helps!

希望能帮助到你!