【发布时间】:2013-08-28 11:16:42
【问题描述】:
<script type="text/javascript">
function printDoc() {
document.getElementById("frame_singleCheque").contentWindow.print();
}
</script>
<iframe style ="height:400px; width: 750px; overflow:scroll;" id="frame_singleCheque" src="http://www.w3schools.com"></iframe>
<input type="button" id = "btnCPrint" value = "Print" onclick="javascript:printDoc()" />
错误
[16:41:44.054] Error: Permission denied to access property 'print' @ http://localhost/pdf/print.php:3
我已经验证了许多堆栈建议线程用于打印 iframe 内容。但对我来说,这些都行不通。
上面的代码只出现在我的 print.php 文件中。我想打印 iframe 内容。
我还想知道,如何打印 iframe 中存在的特定 div。此 iframe 中的示例“class= 'example_code notranslate'”。
【问题讨论】:
-
首先是
focus()window在iframe,然后是print()。 -
您可以访问 iframe 的内容吗?是你的页面吗?
-
您不能将内容注入/获取来自不同域的页面/从它违反安全沙箱的页面。
-
从 HTML5 开始,您可以更好地控制 iFrame。通过使用
sandbox或seamless属性,您可以将 iframe 进一步集成到您的网页中 - w3ctutorial.com/html5-tags/tag-iframe
标签: javascript jquery iframe