I strongly discourage the use <a href="javascript:..something..">
for any purpose, and especially the use of links to perform actions, preferring buttons instead.
If you have
<div>stuff</div>
<div>more stuff</div>
<input type="button" id="print" value="Print this page">
You can later attach a handler to it by using
<script>
document.getElementById("print").addEventListener("click", function() {
if (window.print) window.print();
});
</script>
If you are likely to want a print button on more than that one page, put that code in a .js
file
/* printer.js */
document.getElementById("print").addEventListener("click", function() {
if (window.print) window.print();
});
There are nicer ways to do it if you are using jQuery, but you didn't mention that so I'm avoiding it.
You may want to read the SO question "Correct usage of addEventListener() / attachEvent()" since older versions of Internet Explorer use attachEvent instead of addEventListener.