Javascript 如何打印iframe google文档查看器打开文档
我正在使用谷歌文档查看器来显示我上传的文档,我想打印它,但我不能使用jQuery打印这些文档 我想打印iframe文档,但它不是我的代码。如何打印该文档Javascript 如何打印iframe google文档查看器打开文档,javascript,php,jquery,html,iframe,Javascript,Php,Jquery,Html,Iframe,我正在使用谷歌文档查看器来显示我上传的文档,我想打印它,但我不能使用jQuery打印这些文档 我想打印iframe文档,但它不是我的代码。如何打印该文档 <button id="printbtn" onclick="myFunction()">Print</button> <iframe src="http://docs.google.com/viewer?url=<?php echo urlencode(UPLOAD_URL.$file_name); ?&
<button id="printbtn" onclick="myFunction()">Print</button>
<iframe src="http://docs.google.com/viewer?url=<?php echo urlencode(UPLOAD_URL.$file_name); ?>&embedded=true" frameborder="0" scrolling="no" id="iframe" style="border: none;" width="800" height="470"></iframe>
<script>
function myFunction(){
window.frames["iframe"].focus();
window.frames["iframe"].print(); // NOT WORKING
}
</script>
打印
我做了一些挖掘,发现这是不可能的,
因为docs.google将是一个与你不同的领域。
我试过这个
document.querySelector('iframe').contentWindow.print()
并且“阻止了原点为“”的帧访问交叉原点帧”
比方说,即使谷歌允许跨域名,打印功能也不会起作用。因为谷歌文档查看器会打开另一个打印窗口
我已经得出一个结论,谷歌开发者聪明地使这不可能 我不确定,但这是同一个问题:在这个问题中,显示其他网站的html,但在我的问题中,我打开了word或pdf文件。你使用的是wordpress还是其他?我不知道触发打印命令有那么简单。令人印象深刻。如果由于跨源策略,您正在从另一个域打印iframe元素,那么它将不起作用。