How to remove at Javascript print function? Following is my view page before clicking print button(before fired print function)
View page after clicking print button (after fired print function)
I want to remove link(url) from Edit and delete button which are showing below..
Javascript function
JavaScript
x
9
1
function printDiv(divName)
2
{
3
var printContents = document.getElementById(divName).innerHTML;
4
var originalContents = document.body.innerHTML;
5
document.body.innerHTML = printContents;
6
window.print();
7
document.body.innerHTML = originalContents;
8
}
9
Advertisement
Answer
Easiest way is to add a css class to those and then create a media query for print (if you don’t have it already) and hide them.
For example:
JavaScript
1
3
1
<a class="hide-for-print">Edit</a>
2
<a class="hide-for-print">Remove</a>
3
And then in your style file add this:
JavaScript
1
5
1
@media print {
2
/* All your print styles go here */
3
.hide-for-print { display: none !important; }
4
}
5
Of course you can do it by element but you might not want to hide all a tags when printing.