我有以下函数被锚点调用onclick。它会像我想要的那样打开新窗口,但问题是打印对话框将不会显示,除非open()函数的'URL'
字段为空。想要打开新窗口,然后在该窗口中显示打印对话框
我需要能够打开一个特定的URL('https://www.example.com/file.pdf'
),所以不能留空。
<script>
var pdfw;
function printPdf() {
// pull url
url = document.getElementById('print').getAttribute('href');
console.log("pull");
// open window
pdfw = window.open('', '_blank', 'fullscreen=1,channelmode=1,status=1,resizable=1');
console.log("open");
// print window
pdfw.focus().print();
console.log("print");
}
</script>
带来了新的窗口,因为URL不specificed这当然是空白的,并打印对话框:
pdfw = window.open('', '_blank', 'fullscreen=1,channelmode=1,status=1,resizable=1');
调出显示所需的文件新窗口,但不显示打印对话框:
pdfw = window.open(url, '_blank', 'fullscreen=1,channelmode=1,status=1,resizable=1');
我会说这是某种形式的竞争条件问题,但没有别的使用任何脚本运行在网页打印功能,所以我敢肯定牛逼不是帽子。
任何有关这个问题的帮助或建议将不胜感激!
我试过这种方法,它只是移动打开的新窗口不显示打印对话框。 –
我已经在Chrome上测试了这个,它显示打印对话框 –