打印iframe

时间:2016-06-13 14:57:03

标签: javascript html iframe

报告在定制的Web应用程序中查看,然后应该是可打印的。单击打印图标时,打印预览会显示完全不同的报告。 iframe id似乎是作为一个变量保存的,在看了很多例子之后,我找不到像这样的例子。谁有人建议解决方案?请注意,我没有编写原始代码,但已被要求找到解决方案。

这是功能:

function printReport(printFrameId) {
  if (window.frames[printFrameId].innerHTML != "") {
    window.frames[printFrameId].focus();
    window.frames[printFrameId].print();
  } else {
    setTimeout(printReport,1000);
  }     
}

<div id="reportContent" style="padding-left:25px;padding-right:25px;">
        <?php
        $reportsViewFind = mysql_query($reportSQL);
        $z = 0;
        while($reportView = mysql_fetch_array($reportsViewFind))
        {
            $z++;
            if(empty($reportView["reports_view"]))
            {
                echo '<div id="'.$reportView["reports_run"].'BOX" class="dBox" hidden>
                <h2>PLJ Report</h2>
                <h3>'.$reportView["reports_section"].': '.$reportView["reports_description"].'</h3>
                <div class="errorbox"><b>FAILED REPORT:</b><br>ERROR: Compiler not completed<br>Failed on <a>'.$date.'</a><br><b>0</b> Results</div>
                </div>';
            }
            else 
            {
                if($reportsFilter == "all") { $reportsFrame = $reportView["reports_view"]; } else { $reportsFrame = substr($reportView["reports_view"],0,-4)."_c.php?centre=".$reportsFilter; }
                eval($reportView["reports_view"]);
                echo '<div id="'.$reportView["reports_run"].'BOX" class="dBox" hidden>
                <a href="#"><img src="images/icons/print.png" alt="Print" width="24" height="24" style="float:right;padding-right:10px;margin-top:-30px;" onclick="printReport(\''.$z.'\');" /></a>
                <h2>PLJ Report</h2>
                <h3>'.$reportView["reports_section"].': '.$reportView["reports_description"].'</h3><iframe id="'.$z.'" name="'.$z.'" src="includes/reports/'.$reportsFrame.'" seamless></iframe></div>';
            }
            if($staffdata["staff_type_id"] < 3)
            {
                echo '<div id="'.$reportView["reports_run"].'COM" class="dBox" hidden>
                <a href="#"><img src="images/icons/print.png" alt="Print" width="24" height="24" style="float:right;padding-right:10px;margin-top:-30px;" onclick="printReport(\''.$z.'c\');" /></a>
                <h2>PLJ Comparison</h2>
                <h3>'.$reportView["reports_section"].': '.$reportView["reports_description"].'</h3><iframe id="'.$z.'c" name="'.$z.'c" src="includes/reports/comparison.php?report='.$reportView["reports_id"].'" seamless></iframe></div>';
            }
        }
        ?>
        <div id="missing" class="dBox" style="color:red;" hidden>
        <h2>PLJ Report</h2>
        <h3>Report Error</h3>
        <p>An error occurred when gathering the information for this report. Please close this report and try again.</p>
        </div>
        <div id="missing2" class="dBox" style="color:red;" hidden>
        <h2>PLJ Report</h2>
        <h3>Comparison Error</h3>
        <p>An error occurred when gathering the information for this comparison. Please close this comparison and try again.</p>
        </div>
    </div>

1 个答案:

答案 0 :(得分:0)

感谢所有发布可能解决方案的人,但问题现已解决。我从iframe页面删​​除了打印图标,因为它不起作用。我在php页面上放了一个打印图标,并使用Java Script来打印所需的内容。这是一种享受。