2012-03-20 26 views
3

iframeがネストされていて、内部フレームにonload関数を使用したいと考えています。例えば:別のiframe内の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> 

コード(第2のコールバック):

curFrames[0].contentDocument.getElementByid('the_iframe').onload = finalFrame; 

が実行されることはありません。

そんなことができますか?

コードを実行する前にすべてのフレームがロードされていることを確認します。

おかげ

答えて

2

あなたのウィンドウのツリーとして以下を検討

親ウィンドウ(P1)

----インラインフレーム1(I1)

--------インラインフレーム2(I2)

ここでp1で、コード化したいコードをpfuncとします。

I1で

は、あなたが欲しい、これが行います

function callParent() 
{ 
    parent.callParent(); 
} 

機能の下のウィンドウのonloadコールにI2で

function callParent() 
    { 
     parent.pfunc(); 
    } 

以下のように機能を維持します。

関連する問題