【问题标题】:Printing the HTML from an external Webpage从外部网页打印 HTML
【发布时间】:2016-10-18 08:33:28
【问题描述】:
我正在从外部网页打印 HTML。我做错了吗?
$('#createPDF').on('click',function(){
newWin= window.open("");
newWin.load("http://example.com", function(responseTxt, statusTxt, xhr){
newWin.document.write(responseTxt);
newWin.print();
newWin.close();
});
});
【问题讨论】:
标签:
jquery
pdf-generation
【解决方案1】:
试试这个代码:
$('#createPDF').on('click',function() {
var $trigger = $(this);
$.get('http://example.com', function(data) {
var newWindow = window.open("","_blank");
$(newWindow.document.body).html(data);
newWindow.print();
});
return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="createPDF">
PDF print
</button>
或者这里是一个工作示例 fiddle