Skip to content
Advertisement

How to remove at javascript print function

How to remove at Javascript print function? Following is my view page before clicking print button(before fired print function)

enter image description here

View page after clicking print button (after fired print function)

enter image description here

I want to remove link(url) from Edit and delete button which are showing below..

Javascript function

function printDiv(divName)
{
    var printContents = document.getElementById(divName).innerHTML;
    var originalContents = document.body.innerHTML;
    document.body.innerHTML = printContents;
    window.print();
    document.body.innerHTML = originalContents;
}

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:

<a class="hide-for-print">Edit</a>
<a class="hide-for-print">Remove</a>

And then in your style file add this:

@media print { 
   /* All your print styles go here */
   .hide-for-print { display: none !important; } 
}

Of course you can do it by element but you might not want to hide all a tags when printing.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement