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

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


Pages

    Calendar

    <<  November 2008  >>
    MoTuWeThFrSaSu
    272829303112
    3456789
    10111213141516
    17181920212223
    24252627282930
    1234567

    View posts in large calendar

    Recent comments

    Authors





    Disclaimer

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

    © Copyright 2008

    Sign in