1
我正在打印從後端檢索到的html。如何在使用window.open時停止瀏覽器彈出窗口攔截器
printHtml(htmlTemplate) {
var printWindow = window.open('', '_blank');
printWindow.document.write(htmlTemplate);
setTimeout(function() {
printWindow.document.close(); // necessary for IE >= 10
printWindow.focus(); // necessary for IE >= 10*/
printWindow.print();
printWindow.close();
}, 1000);
}
這工作正常,在所有瀏覽器,只有我想不通的是如何阻止彈出式窗口攔截。 無法使用printWindow.location,因爲html存在於變量中。
你打開這個彈出窗口?用戶操作或其他內容後? _「如果打開選項卡/彈出窗口的命令來自可信事件,則瀏覽器將只打開一個沒有彈出窗口阻止程序警告的選項卡/彈出窗口。」_參見[此問題](http://stackoverflow.com/questions/7139103/open-page-in-new-window-without-popup-blocking)獲取更多詳細信息。 – abhishekkannojia
@abhishekkannojia我從一個按鈕點擊觸發這個,打開瀏覽器打印窗口。 – PAVITRA