另存为和打印对话框似乎无法在PHP中一起工作

时间:2010-07-06 11:14:05

标签: php http-headers

我有一个产品页面列表,我将其导出到word文档,并允许用户打印文档window.print ...我点击ExportToWord按钮saves as对话框打开我取消了...接下来,当我点击打印按钮时,打印对话框会显示一秒钟并且最小化,并且会出现包含单词文档的Saves as对话框...

换句话说:

else if($btn_value == 'word')
        {
            $nam = 'StudentSeatAllot';
            $this->load->library('table');
            $getCollege = $this->adminmodel->getUserCollege();
            $data['viewseatdet']=$this->adminmodel->seatallotreport($college);
            $this->table->set_heading('Degree','Department','Batch',
            'Category','Seatsalloted');
            $out =  $this->table->generate($data['viewseatdet']); 

            //header("Content-type: application/x-ms-download");
            //header("Content-disposition: attachment; filename=$cur_date.doc");
            header("Content-Type: application/vnd.ms-word");
            header("Expires: 0");
            header("Cache-Control:  must-revalidate, post-check=0, pre-check=0");
            header("Content-disposition: attachment; filename=$nam.doc");
            $collegeName = $getCollege[2];
        $collegeAddr1 = $getCollege[5].', '.$getCollege[6].' - '.$getCollege[7];
            $collegeAddr2 = $getCollege[10].', '.$getCollege[8];
            echo '<b><center>'.strtoupper($collegeName).'</b>';
            echo '<br><b>'.strtoupper($collegeAddr1);
            echo '<br><b>'.strtoupper($collegeAddr2).'</center>';
            echo '<br><br>';
            echo 'S E A T  A L L O T - D E T A I L S<br><br>';
            print_r($out);
        }

对于打印我正在使用javascript:

function tablePrint()
{

var display_setting="toolbar=no,location=no,directories=no,menubar=no,";
display_setting+="scrollbars=yes,,status=no,width=750, height=600, left=100, top=25";

var content_innerhtml = document.getElementById("tbl_display").innerHTML;
var document_print=window.open("","",display_setting);
document_print.document.open();
document_print.document.write('<html><head><title>Campus Unified</title><link rel="stylesheet" type="text/css" href="<?=base_url()?>stylesheets/stylesheet.css" /> </head>');
document_print.document.write('<body onLoad="self.print();" >');
document_print.document.write('<center><strong>');
document_print.document.write(content_innerhtml);
document_print.document.write('</strong></center>');
document_print.document.write('</body></html>');
document_print.document.close();

}

![alt text] [1]

第二次编辑: 我的打印按钮,

<button type="submit" class="print" name="print" value="print" onfocus="this.blur();" 
    onclick="tablePrint();">

content_innerhtml

<div id="tbl_display" style="display:none" >
<? if(isset($viewseatdet_print)) { ?>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
    <td colspan="3" align="right" style="padding-right:5px"  class="table_label">Date : <?= date('d-m-Y') ?></td>
</tr>
<tr><td colspan="3" class="table_label" align="center">
<? if(isset($_SESSION['empCollege'])) { $userCollege = $_SESSION['empCollege'];
        echo strtoupper($userCollege[2]).'<br>'.strtoupper($userCollege[5]);
        if(!empty($userCollege[6])){ echo ', '.$userCollege[6]; }
        if(!empty($userCollege[7])){ echo ' - '.$userCollege[7]; }
        if( (sizeof($userCollege))==11)
        { echo '<br>'.strtoupper($userCollege[9]).', '.strtoupper($userCollege[8]); }

    }?>
</td></tr>
</table>

<table ><tr height="10px"><td>&nbsp;</td></tr></table>
<div style="padding-left:4px" class="table_label_header" align="center">
        S E A T S - A L L O T M E N T
</div>
<table width="500px" cellpadding="4" cellspacing="0" border="1" >
    <tr>

            <td style="width:10%" class="grid_header" align="center">Degree</td>
            <td style="width:15%" class="grid_header" align="center">Department</td>
            <td style="width:15%" class="grid_header" align="center">Category</td>
            <td style="width:10%" class="grid_header" align="center">Seatsalloted</td>
    </tr>
    <? if(empty($viewseatdet_print))
 { echo '<tr><td colspan=2>no record found !</td></tr>'; } ?>
    <?  foreach($viewseatdet_print as $row) {  ?>

    <tr>
             <td style="width:10%" class="table_label" align="center"><?= $row['dDegreeName']?></td>
            <td style="width:15%" class="table_label" align="center"><?= $row['dDepartmentName']?></td>
            <td style="width:15%" class="table_label" align="center"><?= $row['dCategory']?></td>
            <td style="width:15%" class="table_label" align="center"><?= $row['dSeatsAllot']?></td>

    </tr>
    <? } ?>

</table>

<? } ?>

</div>

Word HTML:

<button type="submit" class="word" name="word" value="word" onfocus="this.blur();" 
    onclick="return getButtonType('word');">

1 个答案:

答案 0 :(得分:2)

我假设当你点击按钮时,你的发布按钮周围会有一个表单被调用。这个问题解释了,为什么这两件事发生了,你描述了

<button type="submit" [...] onclick="tablePrint(); return false; ">

return false禁用附加到按钮的提交操作。