Printing in JavaScript
May 14, 2008 · Print This Article
Have you ever been asked by customer to create Print button, or “Print Article” feature. I am sure it happened to you, and if not learning something new is always a good thing.
JavaScript does not offer to many way to print, actually there is only one method available to you, it is:
window.print();
JavaScript print function performs the same operation as “Print” function of your browser. You can think that this function is useless, but it is not. It can help you creating more user friendly applications. Below example shows how to print a webpage on button click.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Print Example 1</title> </head> <body> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent nec orci. Cras pellentesque velit a libero. Phasellus est justo, mollis ut, euismod et, consequat a, odio. Maecenas elit neque, tincidunt sed, dignissim vel, molestie eu, justo. Vivamus neque. Suspendisse mollis magna quis tortor. Sed malesuada nisl id velit. Vestibulum vel neque. Nam vestibulum. Donec ultrices dui et dui. In neque. Vivamus ut augue. Aenean lobortis magna ac massa. Suspendisse lacinia. Morbi vulputate pharetra felis. Vestibulum faucibus. Integer mattis elementum metus. Nulla adipiscing dapibus erat. Proin dignissim pharetra dolor. <br/> <input type="button" value="Print" onclick="window.print();" /> </body> </html>
You can check live demo here.
Another handy example of using this function is for web pages that server articles. Many times you want to give users the ability to print the article but without any advertisements or graphics, this can be easily accomplished by creating link like this
<a href="exampleprint2.htm" target="_blank">Print this article</a>
target=”_blank” will open web page in new window. The webpage with article invokes window.print(); in onload event of tag.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Print Example 2</title> </head> <body onload="window.print();"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent nec orci. Cras pellentesque velit a libero. Phasellus est justo, mollis ut, euismod et, consequat a, odio. Maecenas elit neque, tincidunt sed, dignissim vel, molestie eu, justo. Vivamus neque. Suspendisse mollis magna quis tortor. Sed malesuada nisl id velit. Vestibulum vel neque. Nam vestibulum. Donec ultrices dui et dui. In neque. Vivamus ut augue. Aenean lobortis magna ac massa. Suspendisse lacinia. Morbi vulputate pharetra felis. Vestibulum faucibus. Integer mattis elementum metus. Nulla adipiscing dapibus erat. Proin dignissim pharetra dolor. <br/> </body> </html>
You can check live demo here.



















[...] new is always a good thing. JavaScript does not offer to many way to print, actually there is only ohttp://www.rotsystems.com/articles/printing-in-javascriptLinked by Thom Holwerda on Thu 24th Aug 2006 20:25 UTC OS NewsMicrosoft is releasing for public [...]
Pillspot.org. Canadian Health&Care.No prescription online pharmacy.Special Internet Prices.PillSpot.org. Vitamins@buy.online” rel=”nofollow”>.…
Categories: Mental HealthBlood Pressure/Heart.Anti-allergic/Asthma.Antidiabetic.Vitamins/Herbal Supplements.Mens Health.Eye Care.Antidepressants.Antibiotics.Stop SmokingStomach.Skin Care.Weight Loss.Anxiety/Sleep Aid.Antiviral.Womens Health.Pain R…
Canon http://lmichiganotymtxz.copious-systems.com/tag/Toner+PC430+Canon/ : Canon…
Canon…
packets http://kfasconyw4am.BEDROOMPROPERTY.INFO/tag/Baby’s+Breath+packets+Baby/ : packets…
Baby…
buy@generic.LEVITRA” rel=”nofollow”>……
Need cheap generic LEVITRA?…
Purchase@Discount.Coral.Calcium” rel=”nofollow”>..…
Buyit now…
Cheap@Coral.Calcium.Online” rel=”nofollow”>..…
Buygeneric meds…
Buy@Discount.Abana” rel=”nofollow”>..…
Buyno prescription…
Purchase@Discount.Abana” rel=”nofollow”>……
Buywithout prescription…
Cheap@Abana.Online” rel=”nofollow”>..…
Buynow it…
Buy@Discount.Abilify” rel=”nofollow”>……
Buywithout prescription…
Order@Abilify.Online” rel=”nofollow”>.…
Buynow it…
Buy@Acai.Online” rel=”nofollow”>.…
Buywithout prescription…
Buy@Cheap.Acai” rel=”nofollow”>..…
Buydrugs without prescription…
Order@Discount.Acai” rel=”nofollow”>……
Buywithout prescription…
Order@Acai.Without.Prescription” rel=”nofollow”>……
Buynow…
Purchase@Generic.Acai” rel=”nofollow”>……
Buygeneric drugs…
Cheap@Acai.500mg” rel=”nofollow”>..…
Buygeneric drugs…
acai@berry.detox.fort.worth.where.to.buy” rel=”nofollow”>..…
Buygeneric pills…
Buy@Cheap.Coral.Calcium” rel=”nofollow”>.…
Buydrugs without prescription…
Buy@Discount.Coral.Calcium” rel=”nofollow”>.…
Buygeneric meds…
Purchase@Coral.Calcium.Online” rel=”nofollow”>..…
Buygeneric meds…
Purchase@Discount.Coral.Calcium” rel=”nofollow”>……
Buygeneric pills…
Buy@Acai.Online” rel=”nofollow”>.…
Buynow it…
Buy@Acai.Online” rel=”nofollow”>……
Buyno prescription…
Buy@Discount.Acai” rel=”nofollow”>……
Buyit now…
Buy@Discount.Acai” rel=”nofollow”>……
Buygeneric drugs…
Order@Discount.Acai” rel=”nofollow”>……
Buynow…
Purchase@Acai.Online” rel=”nofollow”>……
Buynow it…
Purchase@Cheap.Acai” rel=”nofollow”>……
Buyit now…
Purchase@Cheap.Acai” rel=”nofollow”>..…
Buywithout prescription…
Order@Acai.Without.Prescription” rel=”nofollow”>.…
Buygeneric drugs…
Generic@Acai.500mg.Without.Prescription” rel=”nofollow”>.…
Buyno prescription…
Buy@Cheap.Energy.Boost” rel=”nofollow”>.…
Buygeneric drugs…
Order@Energy.Boost.Online” rel=”nofollow”>.…
Buygeneric drugs…
Purchase@Cheap.Energy.Boost” rel=”nofollow”>.…
Buyno prescription…
Get@Accupril.Online” rel=”nofollow”>.…
Buygeneric drugs…
Purchase@Accutane.Online” rel=”nofollow”>.…
Buynow it…
Purchase@Cheap.Accutane” rel=”nofollow”>.…
Buynow it…
Buy@Aciphex.Online” rel=”nofollow”>.…
Buygeneric pills…
Buy@Generic.Aciphex.Without.Prescription” rel=”nofollow”>.…
Buyno prescription…
Order@Generic.Aciphex” rel=”nofollow”>.…
Buygeneric drugs…
Cheap@Generic.Aciphex.20mg” rel=”nofollow”>.…
Buygeneric drugs…
Order@Acomplia.Online” rel=”nofollow”>.…
Buygeneric meds…
Buy@Actonel.Without.Prescription” rel=”nofollow”>.…
Buygeneric meds…
Purchase@Generic.Actonel.35mg” rel=”nofollow”>..…
Buygeneric drugs krg…
Buy@Discount.Actos” rel=”nofollow”>..…
Buygeneric meds qmo…
Order@Actos.Online” rel=”nofollow”>..…
Buygeneric pills zdg…
Purchase@Cheap.Actos” rel=”nofollow”>..…
Buynow it vhx…
Purchase@Generic.Actos” rel=”nofollow”>.…
Buygeneric drugs zfk…
Cheap@Adalat.Online” rel=”nofollow”>..…
Buywithout prescription dyo…
Buy@Cheap.Coral.Calcium” rel=”nofollow”>……
Buywithout prescription xiu…
Buy@Abana.Online” rel=”nofollow”>..…
Buynow it tly…
Buy@Discount.Acai” rel=”nofollow”>.…
Buygeneric drugs axm…
Order@Discount.Acai” rel=”nofollow”>.…
Buygeneric drugs nih…
Get@Acai.Online” rel=”nofollow”>……
Buynow it zdg…
Buy@Acai.Without.Prescription” rel=”nofollow”>.…
Buygeneric drugs itj…
Purchase@Generic.Acai” rel=”nofollow”>..…
Buydrugs without prescription faj…
Buy@Energy.Boost.Online” rel=”nofollow”>..…
Buynow it cey…
Order@Accupril.Online” rel=”nofollow”>..…
Buyno prescription tao…
Purchase@Accupril.Online” rel=”nofollow”>.…
Buywithout prescription yyn…
Get@Accupril.Online” rel=”nofollow”>..…
Buyit now irl…
Buy@Accutane.Online” rel=”nofollow”>..…
Buyno prescription jui…
Order@Accutane.Without.Prescription” rel=”nofollow”>..…
Buyno prescription gdt…
Purchase@Accutane.Without.Prescription” rel=”nofollow”>.…
Buyit now ojb…
Cheap@Accutane.Without.Prescription” rel=”nofollow”>……
Buydrugs without prescription jlg…
Buy@Cheap.Aciphex” rel=”nofollow”>……
Buywithout prescription ccw…
Buy@Generic.Aciphex.Without.Prescription” rel=”nofollow”>……
Buyit now knc…
Purchase@Generic.Aciphex” rel=”nofollow”>..…
Buydrugs without prescription ygy…
Purchase@Aciphex.Without.Prescription” rel=”nofollow”>.…
Buydrugs without prescription xab…
Purchase@Discount.Acomplia” rel=”nofollow”>……
Buydrugs without prescription ttp…
Purchase@Discount.Acomplia” rel=”nofollow”>.…
Buynow tqa…
Purchase@Discount.Acomplia” rel=”nofollow”>.…
Buydrugs without prescription fva…
Purchase@Discount.Acomplia” rel=”nofollow”>..…
Buynow it xmt…
Buy@Discount.Actonel” rel=”nofollow”>..…
Buyno prescription lka…
Order@Actonel.Online” rel=”nofollow”>……
Buynow fjl…
Buy@Generic.Actonel.Without.Prescription” rel=”nofollow”>.…
Buygeneric drugs ouw…
Buy@Cheap.Advair” rel=”nofollow”>.…
Buygeneric drugs hwi…
Purchase@Advair.Online” rel=”nofollow”>..…
Buyno prescription jui…
Purchase@Cheap.Advair” rel=”nofollow”>.…
Buygeneric pills oir…
Buy@Generic.Advair.Without.Prescription” rel=”nofollow”>..…
Buyno prescription jwi…
Purchase@Generic.Advair” rel=”nofollow”>.…
Buynow it lmg…
Buy@Generic.Advair.25mcg50mcg.25mcg125mcg.25mcg250mcg.50mcg500mcg.50mcg100mcg.50mcg250mcg” rel=”nofollow”>..< …
Buydrugs without prescription hak…
Buy@Discount.Aggrenox” rel=”nofollow”>..…
Buyno prescription wkp…
Order@Aggrenox.Online” rel=”nofollow”>……
Buyit now sge…
coral@calcium.vitamin.explanation” rel=”nofollow”>.…
Buywithout prescription…
hair@growth.and.accutane” rel=”nofollow”>..…
Buygeneric drugs…
acomplia@sleep.apnea” rel=”nofollow”>.…
Buygeneric drugs…
aciphex@cancer.buy” rel=”nofollow”>..…
Buygeneric drugs…
aleve@cold.tablets” rel=”nofollow”>……
Buygeneric pills…
altace@cough.buy” rel=”nofollow”>..…
Buynow…
arava@adverse.events” rel=”nofollow”>……
Buygeneric meds…
coral@calcium.supplements” rel=”nofollow”>……
Buygeneric meds…
can@you.get.acai.berries.in.the.grocery.store” rel=”nofollow”>.…
Buydrugs without prescription…
aciphex@muscle.pain” rel=”nofollow”>..…
Buygeneric pills…
actos@side.effects.edema” rel=”nofollow”>..…
Buygeneric drugs…
..…
Buyit now…
buy@real.strong.armour” rel=”nofollow”>.…
Buydrugs without prescription…
stage 3 ovarian cancer…
Buy_drugs without prescription…
mike divorce cancer tiffany…
Buy_generic pills…
antidepressant drugs for cats…
Buy_generic drugs…
alberta alcohol and drug abuse commission…
Buy_generic meds…
the process of methanogens metabolism…
Buy_drugs without prescription…
boulder valley asthma and allergy clinic…
Buy_no prescription…
drug detection testing…
Buy_generic meds…
recipes for gastric bypass patients…
Buy_now…
citalopram length of use…
Buy_drugs without prescription…
best life diet…
Buy_no prescription…
weight gain stories feeders…
Buy_drugs without prescription…
ept pregnancy test…
Buy_generic meds…
accutane birth defects…
Buy_it now…
menstrual patterns in menopause…
Buy_no prescription…
dependent disorder anxiety…
Buy_generic pills…
indigestion and chest pain…
Buy_now it…
follistim increase estradiol levels…
Buy_generic drugs…
bmi chart for kids…
Buy_generic drugs…
herbal flee collars for dogs…
Buy_generic pills…
buy cheap clomid…
Buy_it now…
what is valtrex used for…
Buy_generic drugs…
hives rash from coming off prednisone…
Buy_generic drugs…
decongestants hypertension safe…
Buy_now it…
cures for fingernail fungi…
Buy_generic meds…
symptoms of chocolate allergy…
Buy_it now…
canine kidney failure symptoms…
Buy_generic pills…
deadliest type of cancer…
Buy_generic pills…
bacterial staphylococcus aureus meningitis symptoms…
Buy_without prescription…
what is metoprolol succinate used for…
Buy_it now…
st joseph aspirin coupon…
Buy_generic pills…
zocor and ms…
Buy_it now…
insulin receptor inhibition…
Buy_without prescription…
adderall then tylenol pm…
Buy_generic drugs…
abdominal pain lutenizing hormone…
Buy_generic drugs…
persistent nausea and stomach pain…
Buy_generic meds…
ic tramadol hcl 50 mg…
Buy_generic meds…
asthmatic inhaller mask for children…
Buy_it now…
cordarone intravenous…
Buy_generic meds…
respiratory infection humidity dry antibiotics avelox…
Buy_generic pills…
find clomid cheap in us…
Buy_now…
hot dog hospital diet substitutions…
Buy_generic drugs…
sample tlc diets…
Buy_generic drugs…
hot spots or cancer…
Buy_without prescription…
cancer chemotherapy combination drugs…
Buy_generic meds…
rebound phenomenon during gradual clonidine withdrawal…
Buy_drugs without prescription…
what causes constant itching…
Buy_generic pills…
kids weight gain…
Buy_generic drugs…
washington university marfan losartan study…
Buy_drugs without prescription…
glucophage powered by vbulletin version 2.2.1…
Buy_generic pills…
psychotic depression and philadelphia…
Buy_generic meds…
shampoo for people with dog allergies…
Buy_now…
interactions with azithromycin and astragalus…
Buy_it now…
menopause thyroid cancer…
Buy_without prescription…
medical nebulizer…
Buy_generic meds…
dog retching vomiting weight loss…
Buy_generic drugs…
boniva and bone thinning and breaks…
Buy_now it…
can iodine help thyroid function…
Buy_generic drugs…
breven medication for add…
Buy_generic drugs…
remeron dreams…
Buy_it now…
fruity taste and diabetes…
Buy_it now…
children@prozac.buy” rel=”nofollow”>……
Buywithout prescription…