我正在尝试打印网页的一部分,并且有多个 css 文件,其中一些文件有助于“打印”媒体类型。我见过的一些插件假设你只有一个 media="print" css 文件,这就是它所需要的。我看过 PrintArea 和 jsprint,对它们中的任何一个都不是很满意,我相信我可以调整它们以获得我需要的东西,但我希望那里有一个更好的库,我还没有发现。
2 回答
看看printThis。它带有几个选项,例如加载 css。
$("#mySelector").printThis({
debug: false, // show the iframe for debugging
importCSS: true, // import page CSS
importStyle: false, // import style tags
printContainer: true, // grab outer container as well as the contents of the selector
loadCSS: "path/to/my.css", // path to additional css file - use an array [] for multiple
pageTitle: "", // add title to print page
removeInline: false, // remove all inline styles from print elements
printDelay: 333, // variable print delay
header: null, // prefix to html
footer: null, // postfix to html
base: false , // preserve the BASE tag, or accept a string for the URL
formValues: true, // preserve input/form values
canvas: false, // copy canvas elements (experimental)
doctypeString: "...", // enter a different doctype for older markup
removeScripts: false, // remove script tags from print content
copyTagClasses: false // copy classes from the html & body tag
});
我只是在看PrintArea 的 source,它似乎确实考虑了多个样式表。如果您告诉我们您不喜欢图书馆的哪些方面,将会有所帮助。
此外,我不确定使用纯 JS 解决方案比使用 PrintArea 之类的插件能够完成多少工作。