我正在从外部网页打印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();
});
});
答案 0 :(得分:0)
试试这段代码:
$('#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
上的工作示例