Related

Denic

File comparison tools

Apache access log file

Quad Boot

Linux commands

Featured

Enea (Ersan Elmasa)

Name

Baby

I AM GETTING MARRIED

Fuck biology

Things I would like to do before death

Newest

MySQL database replace

Award

Graduation

Internet privacy

SSI to php

Random

Hattrick - IV.17 - Mladost 2 : 5 Ersan

Hattrick - Kup V kolo - Ersan 0 : 9 Kroneri

Gradacac (born in) II

SOCIAL READJUSTMENT RATING SCALE

Welcome...

Print, E-mail

Monday, November 17, 2008 11:04:12

Couple of days ago I have had request to implement 'Print this page' and 'E-mail link' to existing website. JavaScript’s print() method is good way to send page to the printer. The print() method is used to print the contents of the current window. The print() method does majority of work, but not all since it is necessary to do some formatting of text prior to sending it to the printer.
This is complete solution with comments:
<script language='JavaScript'>
function send_to_printer()
{
if (document.getElementById != null)
{
var html = '<HTML>\n<HEAD>\n';
html += '<link href=css.css rel=stylesheet type=text/css>\n';
html += '\n</HE>\n<BODY>\n';
html += '<B>Official pages of…</B>';
var print_this = document.getElementById("print_me");
html += print_this.innerHTML;
html += '\n</BO>\n</HT>';
var printWindow = window.open("","send_to_printer ");
printWindow.document.open();
printWindow.document.write(html);
printWindow.document.close();
printWindow.print();
}
}

< /script>
Best would be if above code went inside 'head' tag.

Text that we want to print needs to go inside 'print_me' div.
<div id='print_me'>
This will print...
</div>

Finally, function call:
< a href='javascript:void(send_to_printer ())'>Print</a>


'E-mail link' is shorter and easier. This is javascript function:
function e_mail()
{
var receiver = prompt("Enter e-mail address: ","");
var msg = 'mailto:'+ receiver +'?subject=Some subject&body=' + encodeURIComponent(location.href);
parent.location.href = msg;
}
...and call < a href='javascript:void(e_mail ())'>E-mail</a>



Comments

Your email address:


*Your name:


Your website:


*Please type number shown on the right side of the text box:
verification image, type it in the box

*Comment: