使用javascript将src设置为另一个域的iframe打印到另一个域解决方案
我们已经知道,您无法打印来自其他域的iframe内容。我试图通过在新窗口中打开iframe并在其中打印来解决此问题:使用javascript将src设置为另一个域的iframe打印到另一个域解决方案,javascript,html,iframe,printing,Javascript,Html,Iframe,Printing,我们已经知道,您无法打印来自其他域的iframe内容。我试图通过在新窗口中打开iframe并在其中打印来解决此问题: <body> Other markup on the page that we don't want print here... <input type="button" value="Open window" onclick="openWin()" /> <iframe name="iframeID" src="http://ww
<body>
Other markup on the page that we don't want print here...
<input type="button" value="Open window" onclick="openWin()" />
<iframe name="iframeID" src="http://www.sec.gov/Archives/edgar/data/1490630/000110465914022639/a14-8878_1ex10d1.htm" frameborder="0" style="overflow:hidden;height:100%;width:100%"></iframe>
Other stuff that shouldn't print here...
</body>
有没有办法从url中获取内容以加载到弹出窗口并打印出来?您是否在没有
popWindow.close()的情况下尝试过它?可能是popWindow.print()
是异步的,因此调用会立即返回,close()
会立即发生。我知道了。如果调用print(),它将在触发close()之前等待用户响应。所以print()没有被调用。
<script type="text/javascript">
function openWin()
{
var popWindow=window.open('http://www.sec.gov/Archives/edgar/data/1490630/000110465914022639/a14-8878_1ex10d1.htm','','width=600,height=700');
popWindow.document.close();
popWindow.focus();
popWindow.print();
popWindow.close();
}
</script>
var popWindow=window.open('','','width=600,height=700');