Printing and Previewing Web Page using Link Tag

by Rod 4/15/2008 2:08:00 PM

Print Preview.zip (11.73 kb)

Printing and previewing web page is a common requirement for a web application. The tranditional way of launching a printable version of the form is by using a popup window or sometimes a simple redirect to printable version of the page. This allows the user to preview and print a version of the page without the header and footer, ads, company logo, colorfull graphics, and other printing overheads to save resources (printer ink, paper, etc).

One trick to do this without redirecting or launching a pop-up window is through using <link> tag. Just add a link tag and set the media attribute to print, rel attribute to alternate, and set the href to the path of the printable version of the page then you are done. After adding the link tag, try previewing the page using File | Print Preview menu of your IE browser. In preview window you should see the printable verstion page instead of the current page.

Snippets

      <link rel="alternate" media="print" href="Print.aspx?id=1" />  

I added a query string in href to show that it is possible to provide it to dynamically load content and to reuse the template to other pages. 

The major disadvantage of this approach is that it is only supported IE 6.0 or later browser :(.

Attached is the sample code which includes static and dynamic version.

Cheers!

Rod

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Tips and Tricks

Related posts

Comments

4/15/2008 5:49:09 PM

Chris Ongsuco

Great post, Rod! Very helpful as usual. ;)

Chris Ongsuco ph

4/16/2008 4:21:41 AM

Marvin Trilles

You never cease to amaze us!!!!

Marvin Trilles ph

4/17/2008 4:15:57 AM

Leo Camalig

Nice example sir... Always naman e..

I want to learn about paging, can you write an article and tricks also on it....

Thanks...

Leo Camalig ph

5/25/2008 6:48:52 PM

Joseph De Guzman

Nicely done! I miss working with guys like Rod...you really know the lion by its paw

Joseph De Guzman sg

2/5/2009 9:57:06 PM

Plastic Prototype

Good idea. I usually just set my media to "all" so if someone does print the page, all the dropdowns aren't expanded. This is so much better because it saves on printing all the extra stuff that's not needed. Thanks!

Plastic Prototype us

2/9/2009 7:41:49 AM

Rod

One trick to hide objects you don't want to be printed is to create a css class that hides controls/objects when printed.

<style media="print">
.noPrint { display: none }
</style>

Any data that uses noPrint class will not be printed.

Rod us

3/12/2009 10:46:23 AM

Treasure Islands Bolinao

Thanks for sharing the codes of printing and previewing webpage.

Treasure Islands Bolinao us

5/13/2009 8:40:07 AM

Vinyl Banners

its good know this one from you, good luck

Vinyl Banners us

6/18/2009 7:24:51 AM

Butuan City

thanks for the codes...







http://www.butuanexpats.com

Butuan City ph

7/1/2009 2:01:30 PM

product

Yes, this technique really helps save good money.

product us

7/11/2009 9:00:46 PM

California County Lawyer

Now I knew the different ways in Printing and Previewing Web Page using Link Tags. Thanks for this information

California County Lawyer us

7/16/2009 9:32:00 AM

Social network marketing

Hi,
Search Engine Optimization is a changing field. At any given moment in time, companies that rely on the web for new business or customer communications will consume information about SEO and then rely on that snapshot for months or even years.

Social network marketing us

8/17/2009 5:03:33 PM

Bid Online

Thank you very much for this helpful article! Keep on posting!

Regards

Bid Online us

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

7/29/2010 11:05:44 PM

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen

About the author

Name of author Rod Cerrada
One way to enrich world's treasure is to share your knowledge to younger generations.

E-mail me Send mail  |  LinkedIn  |  ScrumMaster

Company: www.cerquit.com


Recent posts

Pages

    Calendar

    <<  July 2010  >>
    MoTuWeThFrSaSu
    2829301234
    567891011
    12131415161718
    19202122232425
    2627282930311
    2345678

    View posts in large calendar

    Authors






    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010

    Sign in