请帮助我识别,而我不能使用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)
}我打算打印这一页的两个不同的部分。使用this.getIngredientList()打印一个部分,使用innerHTML,而第二个部分中的项列表用于使用innerHTML生成表。
在开始打印时,应用程序生成一个文档,其中包含准确打印所需的信息,但没有显示打印机对话框。
拜托,我有什么不对的?
更新
我变了
winPrint.cardova.plugins.printer.print()
winPrint.close()并显示打印对话框和打印。但是,没有执行winPrint.close()。winPrint= window.open()生成的页面仍然处于打开状态,我不得不迫使应用程序退出。
发布于 2020-03-13 09:33:56
虽然我还没有弄清楚为什么window.close()拒绝被调用/执行,但这是我最终要做的,
const winPrint = (`<!DOCTYPE html>
<html>
<head>
<title>ShopIt</title>
${styleHtml}
</head>
<body>
${prtHtml}`
)
cordova.plugins.printer.print(winPrint, { name: 'report' })我希望这能帮上忙。
https://stackoverflow.com/questions/60556286
复制相似问题