Loading

前端实现打印需求

利用window方法Window.print

  const html = " " //html字符串,要打印的内容
  const iframe: any = document.createElement('iframe')
  iframe.setAttribute('style', 'display:none')
  document.body.appendChild(iframe)
  let title = document.title
  document.title = titleText //自定义打印标题
  let doc = iframe.contentWindow.document
  doc.close()
  iframe.contentWindow.focus()
  doc.write(html)
  iframe.contentWindow.print()
  iframe.parentNode.removeChild(iframe)
  document.title = title

posted @ 2024-11-14 17:13  梧桐树211  阅读(11)  评论(0编辑  收藏  举报