您的位置:首页 > Web前端 > JavaScript

如何打印IFRAME中的内容

2006-11-15 11:00 447 查看
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>
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息