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

My Model View Presenter Experience

by Rod 4/7/2008 12:50:00 AM

Currently I'm working with laser guidance system where we create a Desktop and Mobile version of the application. On the initial requirement the simulator module only required for desktop version. Lately, our client requires us to create a Mobile version of the simulator that way they can simulate using mobile device using different mobile supported ports like bluetooth and other available ports. since I design the simulator in Model View Presenter pattern this is just a piece of cake.

All I have to worry is the UI since mobile application don't have enough space for UI controls so I have to split the UI into pieces.

If I design the MVP layer that is tied up to UI say I added UI reference in my MVP layer I'll probably do a lot of recoding and redesigning. Though mobile application can reuse desktop code but there are several windows forms control that .NET CE does not support.

Cheers!

Rod

Currently rated 5.0 by 1 people

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

Tags:

MVP | My Experience

HTML Help Attribute Extender

by Rod 4/6/2008 9:51:00 PM

HTMLHelpExtender.zip (54.16 kb)

Two years ago I was assigned to a video streaming project that heavily use AJAX using prototype.js. One of the requirement of the application is to create a tooltip for each video thumbnail that shows the description and image of the film when the mouse hovers the thumbnail. In this project I created a javascript code that I have to bind in onmouseover and onmouseout event of the tag. The only disadvantage of this tool is that the I need to manually place the code on both events in each tag that needs a tooltip. There are cases that I forget to place the script for onmouseout that causes the tooltip not to close.

After the project, I made an experment which I usually did if I feel that the problem has a better or best solution. My experiment paid off, their was indeed a better solution. That was when the HTML Help Attribute Extender was born. I was suppose to publish this after I created the tool but I was too busy back then (even my girlfriend got jealous to Tank.. pssstt... secret.. Tank is my laptop's name.. I always give name to my machines, my first computer I named it Einstein, my second machine is Neo, our router is Morpheus, my new IBM is Hotrod.. not because I'm hot its because of my favorite character in Transformer. hehehhe.. Duuhh he is the one who become Rodimus Prime.)

The core of the solution lies on the doument.onmouseover event. I subscribed to the event and manipulate the element and create a timer to automatically close the tooltip.

          document.onmouseover = function(e)
         {

          ...
          }

Downloadattach file for the demo and source code. The source code is documented that way you can extend or customize it. This tool will help your page's tooltip looks professional and slick.

How to use the Help Extender

  1. Download and unzip the file.

  2. Include HelpExtender.js and HelpExtender.css in your application.

  3. Add help attribute in your HTML tag you wish to add a tooltip.

     Ex: <img src="images/question.gif" help="Please enter user details." />

     Figure 1.0. Image help tooltip. 

After adding the help attribute in image tag it will show the help message when the mouse hovers the help icon as shown in Figure 1.0.

Customizing the Help Attribute Extender

  • To customize the look just modify the HelpExtender.css file.
  • To change the width of the tooltip just add a helpToolTipWidth attribute in the tag you wish the width of the tooltip to change.

        Ex: <img src="images/question.gif" help="Please enter user details." helpToolTipWidth="200px" />

  • set the __altToolTipFollowCursor javascript variable to true if you want the tooltip to use mouse cursor position as it's left,top coordinate. If false tooltip will display at the end of the control or tag space (see Figure 1.0 for samle). As default it is set to true.

        <script>

            __altToolTipFollowCursor = false;

        </script>

How to run the demo

   1. Extract the attached sample

   2. Double click the demo.html to launch the demo.

Note: In IE, it sometimes prompt for a security message when you launch the demo from your local drive. Just click "Allow blocked content" to proceed.

Tested under IE 6.0, IE 7.0, and Firefox 2.0.

May the force be with you,

Rod

Currently rated 5.0 by 2 people

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

Tags:

DHTML | Tools

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