PDA

View Full Version : printing within an iframe


allida77
11-26-2002, 07:51 PM
I know how to print and iframe from the parent:

document.frames('iPrint').focus();
document.frames('iPrint').print();

but how do you print from the iframe itself. I am passing an id from the parent to the iframe and then submitting the form on the iframe to call an sub that produces the html content. If I try to print from the parent the sub takes to long to run so it prints a blank page. I am trying to add a print block at the end of the sub so whenver it is through loading it will print itself.

iframe:

<%
Sub mySub()
a bunch of code
'at the end write out javsscript

******THIS IS THE PROBLEM****
<script>window.print()</script> ---doesnt do anything
<script>document.frames('iPrint').focus();
document.frames('iPrint').print();</script> ----throws an error ("Exception")
**************************
End Sub
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<link rel="STYLESHEET" type="text/css" media="print" href="media/print.css">
</HEAD>
<BODY>
<form name="frmPrint" method="post" action="print.asp">
<input type="hidden" name="hdnagtmgrID">
</form>
<%
If Len(Request.Form("hdnagtmgrID")) > 0 Then
AgcyChgs(Request.Form("hdnagtmgrID"))
End If
%>
</BODY>
</HTML>




Thanks in advanvce

allida77
11-26-2002, 09:43 PM
ok I am now just calling a print function on my parent page after the iframe is loaded but I have now run into a bug.


function submitIFrame(id) {
var oifrmNode = document.frames("iPrint").document.frmPrint.hdnagtmgrID
oifrmNode.value = id;
document.frames("iPrint").document.frmPrint.submit();


}

function printIFrame() {
alert("you called");
document.frames('iPrint').focus();
document.frames('iPrint').print();
}


The printIFrame() is what I call from the iframe. The alert msg pops up but it never prints and the status bar on the bottom of the browser slowly chugs along and stops halfway. Any see anything I could change?

allida77
11-26-2002, 10:01 PM
ok I figured it out I should post my problems more often.
FYI:


function submitIFrame(id) {
var oifrmNode = document.frames("iPrint").document.frmPrint.hdnagtmgrID
oifrmNode.value = id;
document.frames("iPrint").document.frmPrint.submit();
document.frames('iPrint').focus();


}

function printIFrame() {
alert("you called");
window.print();
}



The status bar still looks like it is loading something but as long as it works....