[在我无法使用带有此代码的Cordova打印机插件进行打印时,请帮助我识别。
printReport () {
var newstr = document.getElementById('analysis').innerHTML
var div = document.createElement('div')
div.className = 'listPrint'
div.innerHTML = this.getIngredientList()
const prtHtml = '<h4>ShoopiShopping List</h4>'
let styleHtml = ''
for (const node of [...document.querySelectorAll('link[rel="stylesheet"], style')]) {
styleHtml += node.outerHTML
}
const winPrint = window.open('')
winPrint.document.write(`<!DOCTYPE html>
<html>
<head>
<title>ShopIt</title>
${styleHtml}
</head>
<body>
${prtHtml}`
)
winPrint.document.body.append(div)
winPrint.document.write(`${newstr}`)
winPrint.document.write(`</body>
</html>`)
cordova.plugins.printer.print(winPrint)
}
我的意图是打印页面的两个不同部分。使用innerHTML可以按原样打印一个部分,而使用this.getIngredientList()
将第二部分的项目列表用于形成表格在启动打印时,应用程序将生成包含正确打印所需信息的文档,但不会显示打印机对话框。
请,我在做什么不对?
UPDATE
我更改为
winPrint.cardova.plugins.printer.print()
winPrint.close()
并且它显示打印对话框并打印。但是,不会执行winPrint.close()。 winPrint = window.open()生成的页面保持打开状态,我不得不强制退出该应用程序。
尽管,我还没有弄清楚为什么window.close()拒绝被调用/执行的原因,这是我最终要做的,
const winPrint = (`<!DOCTYPE html>
<html>
<head>
<title>ShopIt</title>
${styleHtml}
</head>
<body>
${prtHtml}`
)
cordova.plugins.printer.print(winPrint, { name: 'report' })
我希望这对某人有帮助。