One of the problems that vexed me recently was how to print
the contents of an IFrame when the content changes dynamically.
- 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>"
}
- The document that is loaded in the IFrame should have an “onLoad” event
handler declared - onLoad="javascript:PrintDocument()"
delcared in the "Body" tab - 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/