2016-05-12 3 views
0

私はstackoverflowの熱心なユーザーです。ただ疲れたハハ。プロンプトからループしたiFrame内の入力ボタンのトリガー

私たちが使用している仕事用ポータルの一部に私たちの会社の仕事を投稿するのに役立ついくつかのコードがあります。 (すでにコードを行っています)

当社のCRMのページへのアクセスが制限されています。これが状況です。

  • 私は親の内部で、トップレベルの親

  • でJavaScriptを編集することができIFRAME「app_win」で、その内のiframe「other_frame」です

  • トップで私のコード( "find_other_frame();" 入力のonclick =値= "postjobs")レベルのDIVは、以下の入力 をクリックした後total_jobsをユーザに促すother_fra」で3つのボタンをクリック

  • シミュレート私app_winn '

    私はこだわっています

  • はで次のボタンをクリックしてシミュレートします'。 - 各繰り返しでアラートを追加すると、コードは効果的ですが、アラートなしでは1回だけ実行されます。

    <script language="JavaScript"> 
    
    
          function find_other_frame() { 
           var total_jobs = Number(prompt("How Many Jobs are Currently open?")); 
           var i = 0; 
           while (i < total_jobs) { 
            var iframe1 = document.getElementById('app_win'); 
            var innerDoc1 = iframe1.contentDocument || iframe1.contentWindow.document; 
    
            var iframe2 = innerDoc1.getElementById('other_frame'); 
            var innerDoc2 = iframe2.contentDocument || iframe2.contentWindow.document; 
    
            innerDoc2.getElementById('button1').click(); //job site 1 
            innerDoc2.getElementById('button2').click(); //job site 1 
            innerDoc2.getElementById('button3').click(); //job site 1 
    
            // and then next job - basically a button called next job 
            innerDoc1.querySelector("#smartnav > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(4) > button:nth-child(1)").click(); 
    
            i++; 
    
           }; 
          }; 
    </script> 
    

    なぜループ全体を実行できるようにするにはJavaScriptの一時停止の実行が必要ですか。それは次のボタンが 'app_win'でクリックされるとiframeがリロードされ、 'app_win'のサブiframe 'other_frame'を見つけることができないからですか?

    私は何か。シンプル

  • +0

    あなたがコンソール内の任意のエラーを取得していないでしたコンソールで –

    +0

    ないエラーを改善する必要があると思われる場合 何。コードが実行されるまでの遅延 - ページが完全に読み込まれるようにするには?Document.ready –

    +0

    私は間違っているかも知れないと思う[リンク](http://scottiestech.info/2014/07/01/javascript-fun-looping-with-a-delay/) –

    答えて

    0

    私は解決策を見つけたと思う - 。?あなたはそれがその後、私に知らせてください

    <script language="JavaScript"> 
    
          function find_other_frame_open() { 
           var total_jobs = Number(prompt("How Many Jobs would you like to Post?")); 
           (function theLoop (i) { 
            setTimeout(function() { 
            var iframe1 = document.getElementById('app_win'); 
            var innerDoc1 = iframe1.contentDocument || iframe1.contentWindow.document; 
    
            var iframe2 = innerDoc1.getElementById('other_frame'); 
            var innerDoc2 = iframe2.contentDocument || iframe2.contentWindow.document; 
    
            innerDoc2.getElementById('wpv_1290391').click(); 
            innerDoc2.getElementById('wpv_1290393').click(); 
            innerDoc2.getElementById('wpv_1290340').click(); 
            innerDoc1.querySelector("#smartnav > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(4) > button:nth-child(1)").click(); 
            if (--i) { 
             theLoop(i); 
            } 
            }, 4000); //4 second delay 
           })(total_jobs); 
          }; 
    
          function find_other_frame_close() { 
           var total_jobs = Number(prompt("How Many Jobs Need to Be Closed?")); 
           (function theLoop (i) { 
            setTimeout(function() { 
            var iframe1 = document.getElementById('app_win'); 
            var innerDoc1 = iframe1.contentDocument || iframe1.contentWindow.document; 
    
            var iframe2 = innerDoc1.getElementById('other_frame'); 
            var innerDoc2 = iframe2.contentDocument || iframe2.contentWindow.document; 
    
            innerDoc2.getElementById('thePnetClose').click();      
            innerDoc1.querySelector("#smartnav > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(4) > button:nth-child(1)").click(); 
            if (--i) { 
             theLoop(i); 
            } 
            }, 4000); //4 second delay 
           })(total_jobs); 
          };    
    </script> 
    
    関連する問題