繁体   English   中英

在iFrame中使用提示循环触发触发输入按钮(JavaScript)

[英]Triggering Input Buttons within iFrames with a loop from a prompt (JavaScript)

我是stackoverflow的狂热用户,我总是可以指望数百万的帖子来找到解决方案,但是不知何故我被困在这里,我可能只是累了哈哈。

忙于一些代码,以协助将我们公司的职位发布到我们使用的职位门户的某些付费网站上。 (已经完成该代码)

对我们CRM中页面的访问受限。 就是这种情况。

  • 我可以在顶级父级中编辑JavaScript

  • 父内部是iframe“ app_win”,内部是iframe“ other_frame”

  • 我在顶级div中的代码在单击以下输入后提示用户输入total_jobs(输入onclick =“ find_other_frame();” value =“ postjobs”)

  • 模拟点击“ other_frame”中的3个按钮

  • 模拟单击“ app_winn”中的下一个按钮

我被困在那里。 -如果我在每次迭代中添加一个警报,则代码可以很好地运行,但是如果没有警报,它将仅执行一次。

<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被重新加载,并且代码找不到“ other_frame”-“ app_win”中的子iframe吗?

如果这很简单,请随时向我喊。

我想我找到了解决方案-如果您认为需要改进,请告诉我。

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM