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.

这会按你的意愿做。

更多相关文章

  1. window.open()实现打开窗口
  2. ABP(现代ASP.NET样板开发框架)系列之21、ABP展现层——Javascrip
  3. 为什么括号用于包装javascript函数调用? [重复]
  4. javascript 构造函数中的属性与原型上属性优先级的比较
  5. 在javascript中调用带有双参数()的函数
  6. Objective-C方法/函数调用。 (来自javascript示例)
  7. 将div停靠在窗口左侧并再次单击原始位置
  8. Javascript函数的4种调用方法详解
  9. JavaScript(ES5)使用保留字作函数名

随机推荐

  1. 60分钟精通正则表达式
  2. 在提交注册表单时使用jQuery显示错误
  3. PHP 导出 万级别数据 时间测试
  4. PHP面试题集PHP面试题集
  5. 添加到数据库后,保持在同一页面而不刷新它
  6. 使用jQuery或Javascript重定向到具有值的
  7. 在Web Page中包含PHP代码
  8. 求助,Xdebug的配置,缓存问题。
  9. PHP实现接口方法时出现致命错误
  10. 计算字符串的MD5哈希值