2010-07-26 77 views
0

我試圖拾取一個div的內容,並使用window.open在新窗口中打開它,因此用戶可以打印此打印機友好頁面。我已經得到了網絡上的代碼並做了一些修改。下面是代碼片段打印機友好頁面不能使用IE8

function printpage() { 
     var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
     disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
     var content_vlue = document.getElementById("memo_data").innerHTML; 
     var somestyle = '<style type="text/css"> #memotxt p {padding:0 0 0 0;margin:5px 0 0 0;}</style>'; 

    var docprint=window.open("","sa",disp_setting); 
    docprint.document.open(); 
    docprint.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Inter Office Memo</title>'); 
    docprint.document.write('<link type="text/css" rel="stylesheet" href="../../Content/style.css"'); 
    //docprint.document.write(somestyle); 
    docprint.document.write('</head><body><fieldset style="border:none;"><div class="memo-report-top"');   
    docprint.document.write(content_vlue);   
    docprint.document.write('</div></fieldset></body></html>'); 
    docprint.document.close(); 
    docprint.focus(); 

    } 

,當我打開這個網頁在Firefox它的工作原理完全是應該的方式,但是當我在IE8和觸發的PrintPage()函數按下打印按鈕打開頁面。一個新窗口會彈出醜陋的外觀。我也在打印機友好的頁面中調用了一個css文件,但是當我在IE8開發人員工具中檢查它時,它只顯示了我在應用於body和fieldset時的css屬性。其餘的財產不在那裏。
建議和幫助,高度讚賞
感謝

+0

爲什麼不在彈出窗口中加載相同的頁面,然後使用只打印樣式表來執行樣式? http://www.alistapart.com/articles/goingtoprint/ – Pat 2010-07-26 12:57:59

+0

,因爲這需要另一個css來隱藏頁面的其他部分。我認爲最好在打印頁面上放置必要的內容。 – 2010-07-28 07:09:16

回答

2

div標籤留在下面的代碼行

docprint.document.write('</head><body><fieldset style="border:none;"><div class="memo-report-top"'); 

關閉它解決了這個問題 感謝大家對烏爾輸入
regrds
開放adeel