[英]I am trying to open pdf file in new window and open the print dialog after opening the window
我试图在新的 window 中打开 pdf 文件,并在打开 window 后打开打印对话框,但是打开打印对话框的 print() 方法被跨域异常阻止,返回此错误来源为“ http://localhost:4200 ”的框架访问跨域框架。 我该如何解决这个问题?
print() { var myWindow = window.open('https://mediasb.shiftinc.com/booking_pdfs/QALNHF.pdf', 'Booking', 'width=600,height=600'); myWindow.print(); myWindow.focus(); }
<button (click)= "print()"> Print</button>
在 angular 中执行此操作:-
this.http.get('https://mediasb.shiftinc.com/booking_pdfs/QALNHF.pdf', {responseType: 'blob'}).subscribe((res) => {
let url = window.URL.createObjectURL(res);
var myWindow = window.open(url, 'Booking', 'width=600,height=600');
myWindow.print();
myWindow.focus();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.