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>
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>
本文介绍了一种使用JavaScript从父窗口打印IFRAME内容的方法。关键在于调用print()方法前对IFRAME进行聚焦。文章还提供了一个示例脚本,并区分了Internet Explorer和其他浏览器的操作差异。

被折叠的 条评论
为什么被折叠?



