Javascript – 列印所選取的位置

January 17th, 2012

列印網上資料都會有很多不相關資料在附近, 因此做法有很多
例如:
1. 是開一個page, 用來給人列印, 之後在瀏覽器按列印
2. 有時在css print set display: none, 另周邊資料不顯示
3. 用iframe顯示所需資料之後整一個button 列印 iframe page
但近來看到一些新方法, 看法都簡單所以放上來分享, 第2給自己空閒時用來溫習. 這個方法就是用js解決

function printSelection(node){
var title = ”;
var content=document.getElementById(node).innerHTML;
var pwin=window.open(”,’print_content’,’width=750,height=600,titlebar=no,location=0,toolbar=0,menubar=0,directions=0′);

pwin.document.open();
pwin.document.write(‘<html><head><title>’ + title + ‘</title><style>body table{font-size:10px}</style></head><body onload=”window.print()”>’+content+'</body></html>’);
pwin.document.close();
setTimeout(function(){pwin.close();},1000);
}

 

Javascript, Program , ,

CSS – print next page

June 16th, 2011

page-break-before: always;

CSS, Style ,