SlideShare a Scribd company logo
1 of 9
Download to read offline
Print a Web Page Using JavaScript     http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin...




         Introduction
         home
         about
         non-technical introduction
         newsletter archive
         HTML 5
         html5 development center
         html5 website gallery
         Primers
         html
         social media and html
         ad banners
         perl & cgi
         asp
         javascript
         database - sql
         HTML & Graphics Tutorials
         getting started
         backgrounds
         buttons
         browser specific
         colors
         forms
         frames
         html 4.01 tags
         html 4.01 ref
         image maps
         tables
         web graphics
         Beyond HTML
         asp
         cascading style sheets
         css keyword ref
         cgi scripting


1 of 9                                                                                      5/5/2012 8:14 AM
Print a Web Page Using JavaScript                                 http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin...


         dhtml/layers
         dot net
         java applets
         javascript
         javascript frameworks
         javascript keyword ref
         javascript script tips
         mobile web development
         open source cms
         php
         security
         SEO
         vb script keyword ref
         webmaster tips
         webmaster projects
         webmaster toolbox
         video
         xml
         general reference pieces
         the master list
         Need Help?
         discussion boards
         mentors
         technology jobs
         Web Development
         earthwebdeveloper.com
         javascripts.com
         Looking to reduce IT costs? Learn how to cut expenses without cutting services, plus tactical approaches to
         controlling costs and cutting power expenses outside of the data center. Download now.
         Increase Your Microsoft Office 365 Knowledge! Dig inside this suite of cloud-based collaboration tools. Watch
         the Video>>
                                                                                                                Sponsored

               Post a comment
               Email Article
               Print Article
                  Share Articles
                         Reddit
                         Facebook
                         Twitter
                         del.icio.us
                         Digg
                         Slashdot
                         DZone
                         StumbleUpon
                         FriendFeed
                         Furl
                         Newsvine


2 of 9                                                                                                                  5/5/2012 8:14 AM
Print a Web Page Using JavaScript                                    http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin...


                          Google
                          LinkedIn
                          MySpace
                          Technorati
                          Windows Live
                          YahooBuzz


         Print a Web Page Using JavaScript
         By Joe Burns

            6

            Tweet


            74

            Like

         with updates by HTMLGoodies Editorial Staff

         You've probably been on a web page and wanted to print out the page for later reference. Wouldn't it be great to
         be able to provide visitors to your site to be able to do just that? This tutorial for web developers will show you
         how to use JavaScript's window.print function, complete with examples!

         The JavaScript window.print() Function
         Print is a method of the object "window." At first I thought that the command was simply capturing the buttons
         along the top of the browser window so all I had to do was substitute "print" with one of the other items, like
         "mail" or "home". No dice. I also tried setting up the same type of format with items found in the menus like
         "properties" and "Options." Error after error. It's apparently put into the DTD as a method unto itself.

         Saving Grace!
         The good thing about the command, the way the authors set it up, is that it does not immediately fire a print. It
         actually only fires the print window, which still gives your site's visitors a choice in the matter!




3 of 9                                                                                                                     5/5/2012 8:14 AM
Print a Web Page Using JavaScript                                           http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin...




         It's then up to the person who triggered the method whether to then continue with the printing or not. That's good
         because I can see a ton of problems with printers not being turned on and huge, huge files being set to print.

         So, how to you set up the code? Well, try this first and then look at the code:

         Click to Print This Page

         And here's the code:

         <A HREF="javascript:window.print()">Click to Print This Page</A>

         The JavaScript is triggered by using the command "javascript:" in place of a URL, thus allowing a hypertext link
         to fire off the JavaScript.

         And before you ask, yep, this will work with almost any JavaScript Event Handler as long as the format allows
         you to write it as a specific line or trigger a function.

         You can set it to print off of an image:

         <A HREF="javascript:window.print()">
         <IMG SRC="print_image.gif" BORDER="0"</A>

         It looks like this as an image:




         And yes, you can set it to trigger off a button:

         <FORM>
         <INPUT TYPE="button" onClick="window.print()">
         </FORM>



4 of 9                                                                                                                            5/5/2012 8:14 AM
Print a Web Page Using JavaScript                                      http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin...


         It looks like this as a form button:



         To make sure that your visitors have JavaScript enabled before you provide them with a button that only works
         using JavaScript, you can use JavaScript to print out the button. That way if they have it disabled, no button
         appears, saving them the frustration of clicking a button that does absolutely nothing:

         <SCRIPT LANGUAGE="JavaScript">
         if (window.print) {
         document.write('<form><input type=button name=print value="Print" onClick="window.print()"></form>');
         }
         </script>


         Some Printing Suggestions
         Okay, now you have the power to force a print request, but that doesn't mean to simply offer a print on any page.
         You should make a point of being helpful to your users.

               Make a Page for Printing - The Goodies tutorials, as you can see, have a wavy background, a bunch of
               images, and stuff stuck in all over the place. They're not very good for printing. If I was to offer this page
               for printing, I would make a point of creating basically a text-only page, or at least a page with limited
               images and no background.
               Make the Page Printer-Friendly - I would lose all text colors and make sure the width of the page was no
               more than 500px, left justified, so that what was shown on the screen would print on the printed page in the
               same way.
               Allow the User to Choose to Print - My print offering would be text at the bottom or an icon that doesn't
               intrude. Everyone knows they can already print your pages without any help from your coding. So, make
               this something you offer as a help rather than putting it into people's faces.
               Never Attach This to a User Event - Don't set this to an onLoad, or an onMouseOver, or some other user
               event. It will only tend to upset those who have visited your page and probably stop them from coming
               back.

         Additionally, there are more detailed methods of printing pages that allow you to separate the content from the
         ads, site navigation, etc. This is easier if your content is separate from your site's design, i.e. in a database. We'll
         go into those techniques in a later tutorial!

         That's That...
         There you go. Now you can set up a print request through JavaScript. If used correctly, this is a very nice addition
         to a page and a help to the user, so use it wisely and well.

         Enjoy!


         Test the Code




5 of 9                                                                                                                       5/5/2012 8:14 AM
Print a Web Page Using JavaScript                                   http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin...




         Make a Comment

               Theosaid on April 17, 2012 at 10:55 am

               Can i use the same script for printing just a section of a web page? If not, what is required? Thanks

               Reply

               Venus LUKsaid on March 26, 2012 at 10:55 pm

               my website, which is designed with a title banner, left menu and the content is on the right hand side. The
               point is when i scroll down the content, the left menu and title banner is remain site when scrolling down
               the vertical bar. As I need to add an action for printing, however, it cannot print the full set of the web
               pages, it only show the content but not the title banner and left menu bar, any solution to fix? Thank you for
               your assistance. Thank you very much! Venus

               Reply

               InterDessaid on March 13, 2012 at 1:16 am

               Print a Web Page Using JavaScript http://jqdev.blogspot.in/2012/02/print-web-page-using-javascript.html

               Reply

               Mr Kangsaid on February 22, 2012 at 8:24 pm

               Why window.print() cannot run in IE 6? please help me run print on IE6!

               Reply

               hannah@communicationscouncil.org.ausaid on February 20, 2012 at 4:07 pm

               THANK YOU WORKS SO WELL!!!

               Reply

               Senukasaid on February 3, 2012 at 8:54 am

               Thanks for sharing. Nice day!


6 of 9                                                                                                                    5/5/2012 8:14 AM
Print a Web Page Using JavaScript                                      http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin...


               Reply

               Roedy Greensaid on November 18, 2011 at 2:12 am

               I am looking for a way to print just the form, not the whole web document. I would like to use it to print out
               a customised cheat sheet for Wireshark. See http://mindprod.com/jgloss/wireshark.html I want it to print on
               the client computer, not the server thousands of miles away.

               Reply

                       the_dentistsaid on January 26, 2012 at 3:47 am

                       exactly what i wanted to say. . .only i want to print a div. . .but the principle is the same. . .Roedy, we
                       are great programmers. . .we ask the right questions :D

                       Reply

                               Aaronsaid on January 30, 2012 at 5:27 pm

                               You should see http://stackoverflow.com/questions/468881/print-div-id-printarea-div-only it
                               eliminates the stuff you don't want to print.

                               Reply

               schectersaid on November 16, 2011 at 12:19 am

               is it possible to print the background image ?

               Reply

               Jamessaid on October 12, 2011 at 9:49 pm

               It seems to me that all you really need to do is give the user a link that generates a printer friendly page so
               the user can use the browser's print feature.

               Reply

               rose_of_sharynsaid on October 6, 2011 at 9:51 am

               thanks for this! it really helped me :))

               Reply

               mangsuwu@gmail.comsaid on September 24, 2011 at 9:28 am

               nice bro... thanks

               Reply




7 of 9                                                                                                                       5/5/2012 8:14 AM
Print a Web Page Using JavaScript                                    http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin...


               -said on September 13, 2011 at 6:15 pm

               How do I make a link to print A DIFFERENT WEBPAGE? For example, want to make link to "click to
               print handout". Thank you!

               Reply

                       Nirsaid on September 26, 2011 at 1:26 am

                       Hi, Im hoping I'm understanding your question correctly. Do you want to open a window for a " print
                       preview"? var popUpWindow; popUpWindow.open(do your thing here); popUpWindow.print();
                       popUpWindow.close(); //if you want to close after the user responds to the dialog

                       Reply

               Imransaid on August 25, 2011 at 3:41 am

               Really nice

               Reply

               Ayomidesaid on August 22, 2011 at 8:06 am

               This page is very useful, especially for us up and coming programmers

               Reply

               Kingsaid on June 21, 2011 at 5:26 am

               i have a question.. does it print sets of data that came from database?

               Reply

                       stonesaid on August 15, 2011 at 10:27 am

                       It will print whatever is rendered on the page, by the time a page arrives at your browser where that
                       data came from doesn't matter.

                       Reply

         Read More Comments...

         Web Development Newsletter Signup


         Invalid email
         You have successfuly registered to our newsletter.




8 of 9                                                                                                                     5/5/2012 8:14 AM
Print a Web Page Using JavaScript                                      http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin...




         Canon Printer
         View & Compare Canon Printer Made with
         the latest Technology!
         www.canon.co.id
         ECM output
         Print, email or fax content from popular
         ECM platforms
         www.riptideserver.com/
         JavaScript Developer Tool
         Build business web applications with
         nothing but JS. Free Download.
         www.wakanda.org
         NovaCentrix
         Conductive inks and advanced curing Dry,
         sinter, & anneal at high speed
         www.novacentrix.com

         Related Articles
         So You Want To Open A Window, Huh?
         Hovering HTML Windows and Animated Hovering Using JavaScript
         Creating a Modular JavaScript Toolbox
         Using Multiple JavaScript Onload Functions




                                            Copyright 2012 QuinStreet Inc. All Rights Reserved.

                                        Terms of Service | Licensing & Permissions | Privacy Policy
                                              About the Developer.com Network | Advertise




9 of 9                                                                                                                       5/5/2012 8:14 AM

More Related Content

What's hot

Bootstrap 4 Online Training Course Book Sample
Bootstrap 4 Online Training Course Book SampleBootstrap 4 Online Training Course Book Sample
Bootstrap 4 Online Training Course Book SampleBootstrap Creative
 
How to create tabs in web design
How to create tabs in web designHow to create tabs in web design
How to create tabs in web designChristopher Dill
 
WordPress Optimisation - A4UExpo
WordPress Optimisation - A4UExpoWordPress Optimisation - A4UExpo
WordPress Optimisation - A4UExpoJoost de Valk
 
Style Guides Are The New Photoshop (Fronteers 2012)
Style Guides Are The New Photoshop (Fronteers 2012)Style Guides Are The New Photoshop (Fronteers 2012)
Style Guides Are The New Photoshop (Fronteers 2012)Stephen Hay
 
Using Stylesheets To Design A Web Site In Dreamweaver Mx 2004
Using Stylesheets To Design A Web Site In Dreamweaver Mx 2004Using Stylesheets To Design A Web Site In Dreamweaver Mx 2004
Using Stylesheets To Design A Web Site In Dreamweaver Mx 2004brighteyes
 
HTML5 Dev Conf 2013 Presentation
HTML5 Dev Conf 2013 PresentationHTML5 Dev Conf 2013 Presentation
HTML5 Dev Conf 2013 PresentationIker Jamardo
 
Responsive Web Design - more than just a buzzword
Responsive Web Design - more than just a buzzwordResponsive Web Design - more than just a buzzword
Responsive Web Design - more than just a buzzwordRuss Weakley
 
Web Design 101
Web Design 101Web Design 101
Web Design 101T.S. Lim
 
How to Learn Web Designing Step by Step From Basics in 2018
How to Learn Web Designing Step by Step From Basics in 2018How to Learn Web Designing Step by Step From Basics in 2018
How to Learn Web Designing Step by Step From Basics in 2018Noor Muhammad Khan
 
Balsamiq chrome web app review ui mock ups with balsamiq - mod_monstr
Balsamiq chrome web app review  ui mock ups with balsamiq - mod_monstrBalsamiq chrome web app review  ui mock ups with balsamiq - mod_monstr
Balsamiq chrome web app review ui mock ups with balsamiq - mod_monstrmodmonstr
 
Tips and tricks for the best user-friendly website
Tips and tricks for the best user-friendly website Tips and tricks for the best user-friendly website
Tips and tricks for the best user-friendly website ESRI Bulgaria
 
Planning Your Progressive Web App
Planning Your Progressive Web AppPlanning Your Progressive Web App
Planning Your Progressive Web AppJason Grigsby
 
Gutmacher javascript-bookmarklets-sosuv-july2020
Gutmacher javascript-bookmarklets-sosuv-july2020Gutmacher javascript-bookmarklets-sosuv-july2020
Gutmacher javascript-bookmarklets-sosuv-july2020Glenn Gutmacher
 
Website development
Website developmentWebsite development
Website developmentBrizGo
 
Gutmacher bookmarklets-sosu-europe-oct2018
Gutmacher bookmarklets-sosu-europe-oct2018Gutmacher bookmarklets-sosu-europe-oct2018
Gutmacher bookmarklets-sosu-europe-oct2018Glenn Gutmacher
 

What's hot (20)

Real solutions, no tricks
Real solutions, no tricksReal solutions, no tricks
Real solutions, no tricks
 
Introducing YUI
Introducing YUIIntroducing YUI
Introducing YUI
 
Bootstrap 4 Online Training Course Book Sample
Bootstrap 4 Online Training Course Book SampleBootstrap 4 Online Training Course Book Sample
Bootstrap 4 Online Training Course Book Sample
 
How to create tabs in web design
How to create tabs in web designHow to create tabs in web design
How to create tabs in web design
 
WordPress Optimisation - A4UExpo
WordPress Optimisation - A4UExpoWordPress Optimisation - A4UExpo
WordPress Optimisation - A4UExpo
 
Web Development Life Cycle
Web Development Life CycleWeb Development Life Cycle
Web Development Life Cycle
 
Style Guides Are The New Photoshop (Fronteers 2012)
Style Guides Are The New Photoshop (Fronteers 2012)Style Guides Are The New Photoshop (Fronteers 2012)
Style Guides Are The New Photoshop (Fronteers 2012)
 
Using Stylesheets To Design A Web Site In Dreamweaver Mx 2004
Using Stylesheets To Design A Web Site In Dreamweaver Mx 2004Using Stylesheets To Design A Web Site In Dreamweaver Mx 2004
Using Stylesheets To Design A Web Site In Dreamweaver Mx 2004
 
HTML5 Dev Conf 2013 Presentation
HTML5 Dev Conf 2013 PresentationHTML5 Dev Conf 2013 Presentation
HTML5 Dev Conf 2013 Presentation
 
Responsive Web Design - more than just a buzzword
Responsive Web Design - more than just a buzzwordResponsive Web Design - more than just a buzzword
Responsive Web Design - more than just a buzzword
 
World of WordPress
World of WordPressWorld of WordPress
World of WordPress
 
Web Design 101
Web Design 101Web Design 101
Web Design 101
 
How to Learn Web Designing Step by Step From Basics in 2018
How to Learn Web Designing Step by Step From Basics in 2018How to Learn Web Designing Step by Step From Basics in 2018
How to Learn Web Designing Step by Step From Basics in 2018
 
Balsamiq chrome web app review ui mock ups with balsamiq - mod_monstr
Balsamiq chrome web app review  ui mock ups with balsamiq - mod_monstrBalsamiq chrome web app review  ui mock ups with balsamiq - mod_monstr
Balsamiq chrome web app review ui mock ups with balsamiq - mod_monstr
 
Tips and tricks for the best user-friendly website
Tips and tricks for the best user-friendly website Tips and tricks for the best user-friendly website
Tips and tricks for the best user-friendly website
 
Planning Your Progressive Web App
Planning Your Progressive Web AppPlanning Your Progressive Web App
Planning Your Progressive Web App
 
Gutmacher javascript-bookmarklets-sosuv-july2020
Gutmacher javascript-bookmarklets-sosuv-july2020Gutmacher javascript-bookmarklets-sosuv-july2020
Gutmacher javascript-bookmarklets-sosuv-july2020
 
Website development
Website developmentWebsite development
Website development
 
Gutmacher bookmarklets-sosu-europe-oct2018
Gutmacher bookmarklets-sosu-europe-oct2018Gutmacher bookmarklets-sosu-europe-oct2018
Gutmacher bookmarklets-sosu-europe-oct2018
 
Porfolio
PorfolioPorfolio
Porfolio
 

Similar to Print a web page using java script

Techniques For A Modern Web UI (With Notes)
Techniques For A Modern Web UI (With Notes)Techniques For A Modern Web UI (With Notes)
Techniques For A Modern Web UI (With Notes)patrick.t.joyce
 
Introduction to web design
Introduction to web designIntroduction to web design
Introduction to web designFitra Sani
 
Aucd ppt
Aucd pptAucd ppt
Aucd ppticidemo
 
Introduction to Web Page Design OT and Network
Introduction to Web Page Design OT and NetworkIntroduction to Web Page Design OT and Network
Introduction to Web Page Design OT and NetworkNosajTriumps
 
Don't sh** in the Pool
Don't sh** in the PoolDon't sh** in the Pool
Don't sh** in the PoolChris Jean
 
Skill Session - Web Multi Device
Skill Session - Web Multi DeviceSkill Session - Web Multi Device
Skill Session - Web Multi Devicefilirom1
 
Responsive web design & mobile web development - a technical and business app...
Responsive web design & mobile web development - a technical and business app...Responsive web design & mobile web development - a technical and business app...
Responsive web design & mobile web development - a technical and business app...Atos_Worldline
 
WordPress SEO in 2014 - WordCamp Baltimore 2014
WordPress SEO in 2014 - WordCamp Baltimore 2014WordPress SEO in 2014 - WordCamp Baltimore 2014
WordPress SEO in 2014 - WordCamp Baltimore 2014Arsham Mirshah
 
Design ♥ HTML5 – The Future of Mobile Editorial Design
Design ♥ HTML5 – The Future of Mobile Editorial DesignDesign ♥ HTML5 – The Future of Mobile Editorial Design
Design ♥ HTML5 – The Future of Mobile Editorial DesignJohannes Ippen
 
How to make a great website
How to make a great websiteHow to make a great website
How to make a great websiteDr. Taher Ghazal
 
Your Browser Is The New Photoshop
Your Browser Is The New PhotoshopYour Browser Is The New Photoshop
Your Browser Is The New PhotoshopMatt Puchlerz
 
IE9 for developers
IE9 for developersIE9 for developers
IE9 for developersShaymaa
 
Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3Doris Chen
 
Web Page Designing- Empower Technology.pptx
Web Page Designing- Empower Technology.pptxWeb Page Designing- Empower Technology.pptx
Web Page Designing- Empower Technology.pptxacademicjfurio
 
Mobile Monday Presentation: Responsive Web Design
Mobile Monday Presentation: Responsive Web DesignMobile Monday Presentation: Responsive Web Design
Mobile Monday Presentation: Responsive Web DesignCantina
 
Professional web development with libraries
Professional web development with librariesProfessional web development with libraries
Professional web development with librariesChristian Heilmann
 
Web Development for UX Designers
Web Development for UX DesignersWeb Development for UX Designers
Web Development for UX DesignersAshlimarie
 

Similar to Print a web page using java script (20)

Techniques For A Modern Web UI (With Notes)
Techniques For A Modern Web UI (With Notes)Techniques For A Modern Web UI (With Notes)
Techniques For A Modern Web UI (With Notes)
 
Introduction to web design
Introduction to web designIntroduction to web design
Introduction to web design
 
Aucd ppt
Aucd pptAucd ppt
Aucd ppt
 
Introduction to Web Page Design OT and Network
Introduction to Web Page Design OT and NetworkIntroduction to Web Page Design OT and Network
Introduction to Web Page Design OT and Network
 
Don't sh** in the Pool
Don't sh** in the PoolDon't sh** in the Pool
Don't sh** in the Pool
 
Skill Session - Web Multi Device
Skill Session - Web Multi DeviceSkill Session - Web Multi Device
Skill Session - Web Multi Device
 
Responsive web design & mobile web development - a technical and business app...
Responsive web design & mobile web development - a technical and business app...Responsive web design & mobile web development - a technical and business app...
Responsive web design & mobile web development - a technical and business app...
 
WordPress SEO in 2014 - WordCamp Baltimore 2014
WordPress SEO in 2014 - WordCamp Baltimore 2014WordPress SEO in 2014 - WordCamp Baltimore 2014
WordPress SEO in 2014 - WordCamp Baltimore 2014
 
Design ♥ HTML5 – The Future of Mobile Editorial Design
Design ♥ HTML5 – The Future of Mobile Editorial DesignDesign ♥ HTML5 – The Future of Mobile Editorial Design
Design ♥ HTML5 – The Future of Mobile Editorial Design
 
How to make a great website
How to make a great websiteHow to make a great website
How to make a great website
 
Your Browser Is The New Photoshop
Your Browser Is The New PhotoshopYour Browser Is The New Photoshop
Your Browser Is The New Photoshop
 
IE9 for developers
IE9 for developersIE9 for developers
IE9 for developers
 
Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3
 
Responsive Design
Responsive DesignResponsive Design
Responsive Design
 
TPR4
TPR4TPR4
TPR4
 
TPR4
TPR4TPR4
TPR4
 
Web Page Designing- Empower Technology.pptx
Web Page Designing- Empower Technology.pptxWeb Page Designing- Empower Technology.pptx
Web Page Designing- Empower Technology.pptx
 
Mobile Monday Presentation: Responsive Web Design
Mobile Monday Presentation: Responsive Web DesignMobile Monday Presentation: Responsive Web Design
Mobile Monday Presentation: Responsive Web Design
 
Professional web development with libraries
Professional web development with librariesProfessional web development with libraries
Professional web development with libraries
 
Web Development for UX Designers
Web Development for UX DesignersWeb Development for UX Designers
Web Development for UX Designers
 

Recently uploaded

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Recently uploaded (20)

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

Print a web page using java script

  • 1. Print a Web Page Using JavaScript http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin... Introduction home about non-technical introduction newsletter archive HTML 5 html5 development center html5 website gallery Primers html social media and html ad banners perl & cgi asp javascript database - sql HTML & Graphics Tutorials getting started backgrounds buttons browser specific colors forms frames html 4.01 tags html 4.01 ref image maps tables web graphics Beyond HTML asp cascading style sheets css keyword ref cgi scripting 1 of 9 5/5/2012 8:14 AM
  • 2. Print a Web Page Using JavaScript http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin... dhtml/layers dot net java applets javascript javascript frameworks javascript keyword ref javascript script tips mobile web development open source cms php security SEO vb script keyword ref webmaster tips webmaster projects webmaster toolbox video xml general reference pieces the master list Need Help? discussion boards mentors technology jobs Web Development earthwebdeveloper.com javascripts.com Looking to reduce IT costs? Learn how to cut expenses without cutting services, plus tactical approaches to controlling costs and cutting power expenses outside of the data center. Download now. Increase Your Microsoft Office 365 Knowledge! Dig inside this suite of cloud-based collaboration tools. Watch the Video>> Sponsored Post a comment Email Article Print Article Share Articles Reddit Facebook Twitter del.icio.us Digg Slashdot DZone StumbleUpon FriendFeed Furl Newsvine 2 of 9 5/5/2012 8:14 AM
  • 3. Print a Web Page Using JavaScript http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin... Google LinkedIn MySpace Technorati Windows Live YahooBuzz Print a Web Page Using JavaScript By Joe Burns 6 Tweet 74 Like with updates by HTMLGoodies Editorial Staff You've probably been on a web page and wanted to print out the page for later reference. Wouldn't it be great to be able to provide visitors to your site to be able to do just that? This tutorial for web developers will show you how to use JavaScript's window.print function, complete with examples! The JavaScript window.print() Function Print is a method of the object "window." At first I thought that the command was simply capturing the buttons along the top of the browser window so all I had to do was substitute "print" with one of the other items, like "mail" or "home". No dice. I also tried setting up the same type of format with items found in the menus like "properties" and "Options." Error after error. It's apparently put into the DTD as a method unto itself. Saving Grace! The good thing about the command, the way the authors set it up, is that it does not immediately fire a print. It actually only fires the print window, which still gives your site's visitors a choice in the matter! 3 of 9 5/5/2012 8:14 AM
  • 4. Print a Web Page Using JavaScript http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin... It's then up to the person who triggered the method whether to then continue with the printing or not. That's good because I can see a ton of problems with printers not being turned on and huge, huge files being set to print. So, how to you set up the code? Well, try this first and then look at the code: Click to Print This Page And here's the code: <A HREF="javascript:window.print()">Click to Print This Page</A> The JavaScript is triggered by using the command "javascript:" in place of a URL, thus allowing a hypertext link to fire off the JavaScript. And before you ask, yep, this will work with almost any JavaScript Event Handler as long as the format allows you to write it as a specific line or trigger a function. You can set it to print off of an image: <A HREF="javascript:window.print()"> <IMG SRC="print_image.gif" BORDER="0"</A> It looks like this as an image: And yes, you can set it to trigger off a button: <FORM> <INPUT TYPE="button" onClick="window.print()"> </FORM> 4 of 9 5/5/2012 8:14 AM
  • 5. Print a Web Page Using JavaScript http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin... It looks like this as a form button: To make sure that your visitors have JavaScript enabled before you provide them with a button that only works using JavaScript, you can use JavaScript to print out the button. That way if they have it disabled, no button appears, saving them the frustration of clicking a button that does absolutely nothing: <SCRIPT LANGUAGE="JavaScript"> if (window.print) { document.write('<form><input type=button name=print value="Print" onClick="window.print()"></form>'); } </script> Some Printing Suggestions Okay, now you have the power to force a print request, but that doesn't mean to simply offer a print on any page. You should make a point of being helpful to your users. Make a Page for Printing - The Goodies tutorials, as you can see, have a wavy background, a bunch of images, and stuff stuck in all over the place. They're not very good for printing. If I was to offer this page for printing, I would make a point of creating basically a text-only page, or at least a page with limited images and no background. Make the Page Printer-Friendly - I would lose all text colors and make sure the width of the page was no more than 500px, left justified, so that what was shown on the screen would print on the printed page in the same way. Allow the User to Choose to Print - My print offering would be text at the bottom or an icon that doesn't intrude. Everyone knows they can already print your pages without any help from your coding. So, make this something you offer as a help rather than putting it into people's faces. Never Attach This to a User Event - Don't set this to an onLoad, or an onMouseOver, or some other user event. It will only tend to upset those who have visited your page and probably stop them from coming back. Additionally, there are more detailed methods of printing pages that allow you to separate the content from the ads, site navigation, etc. This is easier if your content is separate from your site's design, i.e. in a database. We'll go into those techniques in a later tutorial! That's That... There you go. Now you can set up a print request through JavaScript. If used correctly, this is a very nice addition to a page and a help to the user, so use it wisely and well. Enjoy! Test the Code 5 of 9 5/5/2012 8:14 AM
  • 6. Print a Web Page Using JavaScript http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin... Make a Comment Theosaid on April 17, 2012 at 10:55 am Can i use the same script for printing just a section of a web page? If not, what is required? Thanks Reply Venus LUKsaid on March 26, 2012 at 10:55 pm my website, which is designed with a title banner, left menu and the content is on the right hand side. The point is when i scroll down the content, the left menu and title banner is remain site when scrolling down the vertical bar. As I need to add an action for printing, however, it cannot print the full set of the web pages, it only show the content but not the title banner and left menu bar, any solution to fix? Thank you for your assistance. Thank you very much! Venus Reply InterDessaid on March 13, 2012 at 1:16 am Print a Web Page Using JavaScript http://jqdev.blogspot.in/2012/02/print-web-page-using-javascript.html Reply Mr Kangsaid on February 22, 2012 at 8:24 pm Why window.print() cannot run in IE 6? please help me run print on IE6! Reply hannah@communicationscouncil.org.ausaid on February 20, 2012 at 4:07 pm THANK YOU WORKS SO WELL!!! Reply Senukasaid on February 3, 2012 at 8:54 am Thanks for sharing. Nice day! 6 of 9 5/5/2012 8:14 AM
  • 7. Print a Web Page Using JavaScript http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin... Reply Roedy Greensaid on November 18, 2011 at 2:12 am I am looking for a way to print just the form, not the whole web document. I would like to use it to print out a customised cheat sheet for Wireshark. See http://mindprod.com/jgloss/wireshark.html I want it to print on the client computer, not the server thousands of miles away. Reply the_dentistsaid on January 26, 2012 at 3:47 am exactly what i wanted to say. . .only i want to print a div. . .but the principle is the same. . .Roedy, we are great programmers. . .we ask the right questions :D Reply Aaronsaid on January 30, 2012 at 5:27 pm You should see http://stackoverflow.com/questions/468881/print-div-id-printarea-div-only it eliminates the stuff you don't want to print. Reply schectersaid on November 16, 2011 at 12:19 am is it possible to print the background image ? Reply Jamessaid on October 12, 2011 at 9:49 pm It seems to me that all you really need to do is give the user a link that generates a printer friendly page so the user can use the browser's print feature. Reply rose_of_sharynsaid on October 6, 2011 at 9:51 am thanks for this! it really helped me :)) Reply mangsuwu@gmail.comsaid on September 24, 2011 at 9:28 am nice bro... thanks Reply 7 of 9 5/5/2012 8:14 AM
  • 8. Print a Web Page Using JavaScript http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin... -said on September 13, 2011 at 6:15 pm How do I make a link to print A DIFFERENT WEBPAGE? For example, want to make link to "click to print handout". Thank you! Reply Nirsaid on September 26, 2011 at 1:26 am Hi, Im hoping I'm understanding your question correctly. Do you want to open a window for a " print preview"? var popUpWindow; popUpWindow.open(do your thing here); popUpWindow.print(); popUpWindow.close(); //if you want to close after the user responds to the dialog Reply Imransaid on August 25, 2011 at 3:41 am Really nice Reply Ayomidesaid on August 22, 2011 at 8:06 am This page is very useful, especially for us up and coming programmers Reply Kingsaid on June 21, 2011 at 5:26 am i have a question.. does it print sets of data that came from database? Reply stonesaid on August 15, 2011 at 10:27 am It will print whatever is rendered on the page, by the time a page arrives at your browser where that data came from doesn't matter. Reply Read More Comments... Web Development Newsletter Signup Invalid email You have successfuly registered to our newsletter. 8 of 9 5/5/2012 8:14 AM
  • 9. Print a Web Page Using JavaScript http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Prin... Canon Printer View & Compare Canon Printer Made with the latest Technology! www.canon.co.id ECM output Print, email or fax content from popular ECM platforms www.riptideserver.com/ JavaScript Developer Tool Build business web applications with nothing but JS. Free Download. www.wakanda.org NovaCentrix Conductive inks and advanced curing Dry, sinter, & anneal at high speed www.novacentrix.com Related Articles So You Want To Open A Window, Huh? Hovering HTML Windows and Animated Hovering Using JavaScript Creating a Modular JavaScript Toolbox Using Multiple JavaScript Onload Functions Copyright 2012 QuinStreet Inc. All Rights Reserved. Terms of Service | Licensing & Permissions | Privacy Policy About the Developer.com Network | Advertise 9 of 9 5/5/2012 8:14 AM