<button onClick="window.print()">Print</button>
window.print();
console.log("print") //or alert("Print")
<p>put text here</p>