|
Print DIV in iframe
My goal is to have a page with an iframe on it. The page in the iframe will have a div. I need a button or link on the main page that will print the contents of the div within the iframe. I know how to print the contents of an iframe from the main page using the code below. I also know how to print the contents of a div on the main page with the code below. I just don't know how to combine the two to print the div in the iframe. Thank you in advance to anyone who can help.
Here is my code to print out the contents of iframe (I1):
<script language=JavaScript>
function CheckIsIE()
{
if (navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER') { return true;}
else { return false; }
}
function PrintThisPage()
{
if (CheckIsIE() == true)
{
document.I1.focus();
document.I1.print();
}
else
{
window.frames['I1'].focus();
window.frames['I1'].print();
}
}
</script>
And here is my code to print contents of a div on the same page as the button or link:
<script language="JavaScript">
var gAutoPrint = true; // Flag for whether or not to automatically call the print function
function printSpecial(name)
{
var name
if (document.getElementById != null)
{
var html = '<HTML>\n<HEAD>\n';
if (document.getElementsByTagName != null)
{
var headTags = document.getElementsByTagName("head");
if (headTags.length > 0)
html += headTags[0].innerHTML;
}
html += '\n</HE' + 'AD>\n<BODY>\n';
var printReadyElem = document.getElementById(name);
if (printReadyElem != null)
{
html += printReadyElem.innerHTML;
}
else
{
alert("Could not find the printReady section in the HTML");
return;
}
html += '\n</BO' + 'DY>\n</HT' + 'ML>';
var printWin = window.open("",name);
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
if (gAutoPrint)
printWin.print();
}
else
{
alert("Sorry, the print ready feature is only available in modern browsers.");
}
}
</script>
|