【问题标题】:Is there a way to send an alert after I print in iFrame? [closed]我在 iFrame 中打印后有没有办法发送警报? [关闭]
【发布时间】:2020-10-07 08:31:56
【问题描述】:

我在 iFrame 中打印后是否可以发送警报?

这是代码。我的代码在 iFrame 中:

function print() { 
    var objFra = document.getElementById('pdf_name'); 
    objFra.contentWindow.focus(); 
    objFra.contentWindow.print(); 
}

我试过了

objFra.contentWindow.addEventListener('afterprint', () => { alert('This document is now being printed })

但未显示警报。

【问题讨论】:

  • 在哪里发送警报?你的意思是屏幕上只有alert()
  • 是的,它尝试了 objFra.contentWindow.addEventListener('afterprint', () => { alert('This document is now being print })
  • 但它没有返回警报

标签: javascript php iframe printing


【解决方案1】:

试试这个:

var objFra = document.getElementById('pdf_name'); 
 
objFra.contentWindow.addEventListener('afterprint', () => { 
    alert('This document is now being printed'); 
}); 

objFra.contentWindow.focus();
objFra.contentWindow.print();

JSFiddle

【讨论】:

  • 我已经尝试过该代码,但整个正文都在打印而不是我想要的 iframe
猜你喜欢
  • 2020-07-14
  • 2021-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-11
  • 2022-12-06
  • 1970-01-01
  • 2019-07-08
相关资源
最近更新 更多