2010-07-26 36 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