Simple print button

  • Thread starter Thread starter Mettá
  • Start date Start date
I can't imagine what's wrong with the browser's Print button or File Print
command, but try:

<a href="javascript:window.print();">Print</a>

Jim Buyens
Microsoft MVP
http://www.interlacken.com
Author of:
o-----------------------------------------------------
o--> Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site
Now!
o--> Microsoft Office FrontPage 2003 Inside Out
o--> Microsoft Windows SharePoint Services Inside Out
o--> Faster Smarter Beginning Programming
o-----------------------------------------------------
 
Fails on IE5/Mac.

Here's the best you can do -

Put this in the head of the document -

<script type="text/javascript">
function print_page(where){
var is_mac=(navigator.platform.indexOf("ac") != -1);
(document.all && is_mac)?
alert("Select \"Print\" from the menu") : where? where.window.print() :
window.print();
}

function writeOutPrintLink(){
document.getElementById('printLink').innerHTML = '<a
href="javascript:print_page();">Print this</a>'

}

</script>

Adjust the body tag of the document as follows -

<body ... onload="writeOutPrintLink();"> (where the ellipsis indicates
already existing attributes, if any)
<span id="printLink"></span>

That way, the link only shows up if you have javascript enabled.
 
Back
Top