另一个iframe中的iframe的onload函数
16lz
2021-01-22
I have nested iframes and I would like to use onload function for the inside frame. For example:
我有嵌套的iframe,我想使用内部框架的onload函数。例如:
<script type="text/javascript">
var testing = 'test';
var curFrames;
var curUrl;
var mFrames;
var cFrame;
var editor;
var editor2;
window.onload=CodeOnLoad;
//Javascript that runs on load
function CodeOnLoad() {
curFrames=document.getElementsByTagName("frame");
console.log(curFrames[0])
//onload for 1st frame
curFrames[0].onload = getInside;
function getInside() {
//onload for second frame - Not working
curFrames[0].contentDocument.getElementByid('the_iframe').onload = finalFrame;
}
function finalFrame() {
curUrl= curFrames[0].contentDocument.getElementById("the_iframe").src;
console.log(curUrl);
if (curUrl.indexOf("post")!=-1)
{
mFrames=document.getElementsByTagName("frame");
cFrame = mFrames[0].contentDocument.getElementById('the_iframe');
editor = cFrame.contentWindow.tinymce.activeEditor;
console.log(editor);
}
}
}
</script>
The code (second callback):
代码(第二个回调):
curFrames[0].contentDocument.getElementByid('the_iframe').onload = finalFrame;
is never executed.
从未被执行过。
Is it possible to do it like that?
有可能这样做吗?
I want to ensure that all frames are loaded before executing any code.
我想确保在执行任何代码之前加载所有帧。
Thanks
谢谢
1 个解决方案
#1
2
Consider below as your window tree
请将以下视为您的窗口树
Parent Window (P1)
父窗口(P1)
----Iframe 1 (I1)
---- iframe 1(I1)
--------Iframe 2 (I2)
-------- iframe 2(I2)
Now in p1, keep function say pfunc, in which you code whatever you want to code
现在在p1中,保持函数说pfunc,在其中编码你想要编码的任何代码
in I1 keep a function as below
在I1保持功能如下
function callParent()
{
parent.pfunc();
}
in I2 on window onload call below function
在I2上窗口onload调用下面的函数
function callParent()
{
parent.callParent();
}
this will do as you want.
这会按你的意愿做。
更多相关文章
- window.open()实现打开窗口
- ABP(现代ASP.NET样板开发框架)系列之21、ABP展现层——Javascrip
- 为什么括号用于包装javascript函数调用? [重复]
- javascript 构造函数中的属性与原型上属性优先级的比较
- 在javascript中调用带有双参数()的函数
- Objective-C方法/函数调用。 (来自javascript示例)
- 将div停靠在窗口左侧并再次单击原始位置
- Javascript函数的4种调用方法详解
- JavaScript(ES5)使用保留字作函数名