iframe仅在加载一页后才在循环中设置src

时间:2018-06-26 00:41:22

标签: loops iframe synchronized src

我正在iframe中(一张一张地)打开多个页面,即我想同步进行。因此,在for循环中,我想将iframe src属性设置为url1,然后在加载此页面后移至url2,依此类推。

<iframe id="iframeExportPDF" onload="test();"></iframe>

$('#<%=Button1.ClientID%>').click(function (e) {
        e.preventDefault();

        var registrarIds = ($('#<%=lblRegistrarIdsForChart.ClientID%>').text()).split(',');

        for (var i = 0; i < registrarIds.length; i++) {
            var link = window.location.href;
            var urlBase = link.substring(0, link.lastIndexOf("/") + 1);
            //alert(registrarIds[i].toString());
            ganttPopup(urlBase + 'GPS/CompetencyAssessment/GanttChart.aspx?id=' + registrarIds[i].toString(), registrarIds[i]);
            sleep(25000);
        }
    });

    function ganttPopup(url, id) {
    iframeExportPDF.src = url;
    //window.open(url, "_blank", "ganttChartPopup_" + id.toString(), "width=1100,height=600,scrollbars=yes,resizable=yes");
}

P.S。以前我在打开多个窗口时也做同样的事情,但是由于我有1100条记录,所以window.open将不可行。

1 个答案:

答案 0 :(得分:0)

我找到了答案here

var urls = [], iCount;

$(function () {
    $('#<%=Button1.ClientID%>').click(function (e) {
        e.preventDefault();

        var registrarIds = ($('#<%=lblRegistrarIdsForChart.ClientID%>').text()).split(',');
        iCount = registrarIds.length;

        for (var i = 0; i < registrarIds.length; i++) {
            var link = window.location.href;
            var urlBase = link.substring(0, link.lastIndexOf("/") + 1);
            var url = urlBase + 'GPS/CompetencyAssessment/GanttChart.aspx?id=' + registrarIds[i].toString();
            urls.push(url);
        }



        redirect_url();
   });

  function redirect_url() {
        if (iCount >= 0) {
            setTimeout(function () {
                $('#iframeExportPDF').attr('src', urls[iCount]);
                iCount--;
                redirect_url();
            }, 15000);
        }
    }
});