如何打印IFRAME中的内容

: Here's a quick little tip that demonstrates how to print the contents of an IFRAME from the parent window using JavaScript. I've seen on several discussion forums that this isn't possible when it is. The key item to notice is that we set focus() to the IFRAME just before issuing the print() method.

Please take a moment to rate this tip: http://www.turnkeytools.com/polls/default.asp?POLLID=10000086&DOMAINID=4610


<script language=JavaScript>

function CheckIsIE()
{
if (navigator.appName.toUpperCase() == 'MICROSOFT
INTERNET EXPLORER') { return true;}
else { return false; }
}


function PrintThisPage()
{

if (CheckIsIE() == true)
{
document.ifWorkspace.focus();
document.ifWorkspace.print();
}
else
{
window.frames['ifWorkspace'].focus();
window.frames['ifWorkspace'].print();
}

}

</script>

In the parent window, just put a link or button to call the PrintThisPage() method:

<a href="javascript:PrintThisPage();" >Print This Page</a>
posted @ 2006-09-19 17:14  QDuck  阅读(2053)  评论(0编辑  收藏  举报