Click here to Skip to main content
15,902,492 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want to remove url and page number from header and footer while i am using javascript print command so that i can only print particular div content .
I have use this javascript function
:
<script language="javascript">
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;

document.body.innerHTML = printContents;

window.print();

document.body.innerHTML = originalContents;
}

</script>
Thanks
Posted

The URL and page number is added by IE, not by your page, right? You have to turn off the setting in page setup in IE.
 
Share this answer
 
<script language="javascript">
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.getElementById('header').style.display = 'none';
document.getElementById('footer').style.display = 'none';
document.body.innerHTML = printContents;

window.print();


document.body.innerHTML = originalContents;
}

</script>
<div id="div_print">
<div id="header" style="background-color:White;"></div>
<div id="footer" style="background-color:White;"></div>
</div>
This is called Solution .
 
Share this answer
 
Comments
David Prout 26-Sep-18 0:35am    
It still prints the URL at the top and page number. The above solution does nothing useful.

@media print {
@page { margin: 0; }
body { margin: 1.6cm; }
}

Works on Chrome by forcing Chrome's headings off the page....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900