简体   繁体   中英

Printing a particular portion of a page

I am using this code to print a specific div inside a page

var printCalender = function ()
{
    var headstr = "<html><head><title></title></head><body>";
    var footstr = "</body>";
    var newstr = "<div style='text-align:center'><h2>Academic Calender - " + $scope.selectedSessionSelection + "</h2></div><br /><br />" + document.all.item('printportion').innerHTML;
    var oldstr = document.body.innerHTML;
    document.body.innerHTML = headstr + newstr + footstr;
    window.print();
    document.body.innerHTML = oldstr;
    return false;
}

The problem is that, if I cancel printing, then I cannot execute any javascript on the page.

Use a Print only CSS file:

<link rel="stylesheet" type="text/css" href="print.css" media="print">

This will only be read in print mode.

Then you can manipulate styles for print only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM