2015-04-20 35 views
0

我有一個關於閱讀網頁然後打印彈出式副本的問題。無法將格式設置爲javascript

基本上我在A頁上有一個表格。如果用戶選擇通過支票付款,他們的發票將彈出一個新的窗口B,這是一個打印預覽。 A上的發票表格格式良好。不幸的是,在彈出的打印頁面B中,表格格式(實際上所有的頁面格式)都沒有了。也就是說,第一列的居中和第二,行着色和表格邊界的右對齊。

我想創建3個div;一張之前,一張之後,一張包括髮票,但是我所有的嘗試都給出了格式不正確的表格。然後我想我會在頁面A中使用div進行重寫,並重寫彈出式打印機頁面以反映此情況(將多個字符串寫爲strHeader,strTable,strFooter)。關於如何繼續進行的任何想法?

這裏是我的代碼:

<script type="text/javascript"> 
function printContent(id){ 
str=document.getElementById(id).innerHTML 
newwin=window.open('','printwin','left=100,top=100,width=1000%,height=1000%') 
newwin.document.write('<HTML>\n<HEAD>\n') 
newwin.document.write('<TITLE>Print Page</TITLE>\n') 
newwin.document.write('<script>\n') 
newwin.document.write('function chkstate(){\n') 
newwin.document.write('if(document.readyState=="complete"){\n') 
newwin.document.write('window.close()\n') 
newwin.document.write('}\n') 
newwin.document.write('else{\n') 
newwin.document.write('setTimeout("chkstate()",2000)\n') 
newwin.document.write('}\n') 
newwin.document.write('}\n') 
newwin.document.write('function print_win(){\n') 
newwin.document.write('window.print();\n') 
newwin.document.write('chkstate();\n') 
newwin.document.write('}\n') 
newwin.document.write('<\/script>\n') 
newwin.document.write('</HEAD>\n') 
newwin.document.write('<BODY onload="print_win()">\n') 

newwin.document.write("<b><font size= '6' >" + 'Event Registration' + " </font></b>") 
newwin.document.write(str) 
newwin.document.write('footer info goes here') 

newwin.document.write('</BODY>\n') 
newwin.document.write('</HTML>\n') 
newwin.document.close() 
} 
</script> 

<?php $this->set('title_for_layout', 'Event Registration Payment')?> 
<?php if($eventRegistration['EventRegistration']['payment_type'] =="cheque"):?> 
<b>To pay by cheque...</b><a href="#null" onclick="printContent('print_div1')"> click here</a> 
<?php endif;?> 

<DIV id="print_div1" style="border:1px solid #000000"> 

<?php echo $this->Session->flash(); ?> 
<?php echo $this->requestAction('/liveEditRegions/getRegion/60'); ?> 

<table class="invoiceTable" style="margin-bottom: 10px;"> 
<tr class="titleRow"> 
<th class="center">Item</th> 
<th class="center">Price</th> 
</tr> 

<!-------------------------------------registration--> 
<?php if($registrationPrice > 0):?> 
<tr> 
    <th class="center">Registration Price</th> 
    <td class="right">$<?php echo number_format($registrationPrice, 2) ?></td> 
</tr> 
<?php endif;?> 

<!-------------------------------------------events--> 
<?php if($eventRegistration['EventRegistration']['dinner_ticket_number'] > 0):?> 
<tr> 
    <th class="center">Dinner Ticket(s) x <?php echo  $eventRegistration['EventRegistration']['dinner_ticket_number']?> @ $<?php echo number_format($eventRegistration['EventRegistration']['dinner_ticket_price'])?></th> 
    <td class="right">$<?php echo number_format($dinnerticketTotal, 2) ?></td> 
</tr> 
<?php endif;?> 

<?php if($eventRegistration['EventRegistration']['student_social_ticket_number'] > 0):?> 
<tr> 
    <th class="center">Student Social Ticket(s) x <?php echo $eventRegistration['EventRegistration']['student_social_ticket_number']?> @ $<?php echo number_format($eventRegistration['EventRegistration']['student_social_ticket_price'])?></th> 
    <td class="right">$<?php echo number_format($ssticketTotal, 2) ?></td> 
</tr> 
<?php endif;?> 

<tr> 
<th class="right">Sub total</th> 
<td class="right">$<?php echo number_format($subtotal, 2); ?></td> 
</tr> 
<tr> 
<th class="right">TAX</th> 
<td class="right">$<?php echo number_format($tax, 2); ?></td> 
</tr> 
<tr> 
<th class="right">Total</th> 
<td class="right">$<?php echo number_format($total, 2); ?></td> 
</tr> 
</table> 

<!-----------------------------------------CHOOSE PAYMENT--> 
<?php if($eventRegistration['EventRegistration']['payment_type'] =="credit card"):?> 

[snip] 

<?php endif;?> 

<?php if($eventRegistration['EventRegistration']['payment_type'] =="cheque"):?> 
<?php endif;?> 
</DIV> 
+0

給倒票的用戶:你錯了。我做了大量的研究,這是什麼把我帶到這裏。如果您有建設性的批評,請提出搜索條件或重複查詢。我覺得這很清楚,編碼包含在內,並得到很好的評論。對我來說,這顯然是有用的。我不敢相信這將不會有其他用途。 – mellofellow

+0

我有另一個不雅的解決方案;基本上我可以讀取表變量,然後手動重新創建js表。這將是一個痛苦,似乎應該有更好的辦法。 – mellofellow

+0

我嘗試閱讀頁面,按章節解析,然後替換表格格式元素(例如「中心」 - >「右側」),但它似乎對最終格式沒有影響。 – mellofellow

回答

1

嘗試看是否有一個CSS樣式表overiding更改。也許在新頁面上明確地創建一個表格樣式來進行仔細檢查。

+0

謝謝我會試試這個。 – mellofellow