I have a print button with the below code:
<script type="text/javascript"> \\this hides the print & close buttons while printing
function printpage() {
//Get the print button and put it into a variable
var printButton = document.getElementById("print");
var closeButton = document.getElementById("close");
//Set the print button visibility to 'hidden'
printButton.style.visibility = 'hidden';
closeButton.style.visibility = 'hidden';
//Print the page content
window.print()
//Set the print button to 'visible' again
//[Delete this line if you want it to stay hidden after printing]
printButton.style.visibility = 'visible';
closeButton.style.visibility = 'visible';
}
</script>
<button type="button" id="print" class="btn btn-danger" onclick="printpage()">Print</button>
<button type="button" id="close" class="btn btn-danger" data-dismiss="modal">Close</button>
now it works and opens the print page and hides the buttons but its trying to print the whole page but i only need it to print the content in the div section "myModal"
I tried this and it did what i wanted but after printing the X in the active window doesn't work to close it nor do the buttons.I have to refresh the page with F5 to get back to the main window:
function printContent(el){
var restorepage = document.body.innerHTML;
var printcontent = document.getElementById(el).innerHTML;
document.body.innerHTML = printcontent;
window.print();
document.body.innerHTML = restorepage;
}