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

Add comment


(Will show your Gravatar icon)  

  Country flag

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



Live preview

11/21/2008 2:27:36 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


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