Showing posts with label print IFrame. Show all posts
Showing posts with label print IFrame. Show all posts

Thursday, May 24, 2007

Printing the contents of a IFrame whose content changes dynamically

One of the problems that vexed me recently was how to print

the contents of an IFrame when the content changes dynamically.


  1. Here is my solution:

    Declare a DIV area in the body of the HTML document with an ID attribute value of
    "IFrameArea".

    Declare a JavaScript function that dynamically assigns an IFrame as the innerHTML
    property of the DIV. Note that the dimensions of the IFrame are small. This
    has the effect of making it invisible.


function PrintIFrame(SRC)

{
var URL;

URL = (SRC).toString();

document.getElementById('IFrameArea').innerHTML = "<iframe src='"

+ URL + "' height='1' width='1' frameborder='0' ID='MyIFrame' name='MyIFrame'>
</iframe>"

}



  1. The document that is loaded in the IFrame should have an “onLoad” event
    handler declared
    1. onLoad="javascript:PrintDocument()"
      delcared in the "Body" tab
  2. The document that is loaded in the IFrame should have a a function to perform
    the printing


function SetupToPrint()

{
parent.frames.PrintCounter.focus();
window.print();
}

Refer your friends to this blog:

http://programmingcentral.blogspot.com/