例如我有这个功能:
function getPrintedHTML()
{
//...
return some_html_code;
}
我知道我可以使用window.print()
打印整个页面,但它打印整个页面。
有什么办法可以打印函数结果吗?
附注打印而不将此 html 添加到正文。
最佳答案
您可以尝试使用iframe
:
var i = document.createElement('iframe');
i.onload = function() {
i.contentDocument.body.innerHTML = someHtml;
i.contentWindow.print();
setTimeout(function() {
document.body.removeChild(i);
}, 0);
};
document.body.appendChild(i);
关于javascript - 如何打印由其中一个函数生成的特定 html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26042978/