css .noprint,javascript - window.print() CSS not loaded in print preview - Stack Overflow

I need to provide option to print a part of the webpage. This was implemented using the javascript window.print() answered by: Bill Paetzke.

The pop up window opens up (this contains CSS style) and the print dialog also opens. But the CSS style does not show up in the print.

Tried @media =print but that also does not work.

CSS style mainly consists of background color. One option that I got was to replace the background color with an image of 1px * 1px and repeat it. Is there any other way?

Browser: IE7

Code:

.hideMe{

display:block;

}

.PrintClass {

display:block;

}

.NoPrintClass{

display:block;

}

function PrintElem(elem)

{

Popup($('

}

function Popup(data)

{

var mywindow;

mywindow = window.open('', 'mydiv','height=400,width=600,scrollbars=yes','');

mywindow.document.write('

my div');

mywindow.document.write('');

mywindow.document.write('

');

mywindow.document.write('drop down selected value in parent: '+mywindow.opener.document.getElementById('testSelect').options[mywindow.opener.document.getElementById('testSelect').selectedIndex].text+'
');

mywindow.document.write('contentStarts
');

mywindow.document.write(' using jquery: '+data);

mywindow.document.write(' using javascript: '+mywindow.opener.document.getElementById('mydiv').innerHTML);

mywindow.document.write('
contentEnds');

mywindow.document.write('
');

mywindow.document.write('');

mywindow.document.focus();

mywindow.document.close();

mywindow.print();

return true;

}

This is not be printed

This content is to be printed

1

2

3

This will also be printed


print bgcolor

print
print
not to print
not to print
print
print


print image

print
print
not to print
not to print
print
print

some text

green.pngdfads

wpeoriu
This will not be printed.
Nor will this.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值