chrome自定义内容打印/save pdf (不打开新页面)

var $iframe = $("<iframe />");
$iframe.appendTo("body");
var doc = $iframe[0].contentWindow.document;


var bootstrapCss = '<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">';
var customCss = '<link rel="stylesheet" href="http://' + location.host + '/css/custom.css">';
doc.head.innerHTML = bootstrapCss + customCss;
doc.body.innerHTML = $('#printElement')[0].outerHTML;


setTimeout(function () {
$iframe[0].contentWindow.print();
$iframe.remove();
})

猜你喜欢

转载自blog.csdn.net/qq_33576343/article/details/80883455
今日推荐