这是我使用的代码,在firefox和chrome中都可以正常使用,不幸的是safari不支持这个对话框出现后立即关闭。这个问题有什么解决办法吗?
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write(
'<html style="background-color: white;"><head><title></title>');
mywindow.document.write(
'<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/queue.css">'
);
mywindow.document.write(
'</head><body style="background-color: white !important;padding-top:15px;margin:2">'
);
mywindow.document.write(document.getElementById('forprint').innerHTML);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
mywindow.close();
return true;
最佳答案
Safari 阻止对 window.open() 的调用(异步调用)在进行 asnyc 调用之前先调用 window.open 然后设置位置(当 promise 已解决时):
var newWindow = window.open();
var url = "[YOURURL]";
service.getUrl().then(function(url) {
newWindow.location = url;
});
关于Javascript 打印 div 在 Safari 网络浏览器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50055604/